문제 출처 : https://www.acmicpc.net/problem/9494
언어 : Kotlin
문제 설명 :
Take some text. Put a small ball at the top of the first letter of the first word of the first sentence. The ball is drawn via gravity downwards. The text is also at a slight angle, so the ball wants to also move towards the right. The ball can freely move between the lines, and can drop through spaces. Considering the first column to be column 1, what column will the ball end up in? In this example, the ball ends up in column 8.
입력 :
There will be several test cases in the input. Each test case will begin with an integer n (1≤n≤1,000) on its own line, indicating the number of lines of text. On each of the next n lines will be text, consisting of printable ASCII characters and spaces. There will be no tabs, nor any other unprintable characters. Each line will be between 1 and 100 characters long. The input will end with a line containing a single 0.
출력 :
For each test case, output a single integer on its own line, indicating the column from which the ball will drop. Output no spaces, and do not separate answers with blank lines.
제한 사항 :
- 시간 제한 : 1초
- 메모리 제한 : 128MB
입출력 예 :
입력 | 출력 |
4 Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. 3 Supercalifragilisticexpialidocious! Can you handle short lines? 0 |
8 36 |
풀이 :
import java.io.BufferedReader
import java.io.BufferedWriter
import java.io.InputStreamReader
import java.io.OutputStreamWriter
fun main() = with(BufferedReader(InputStreamReader(System.`in`))) {
val bw = BufferedWriter(OutputStreamWriter(System.out))
var idx: Int
var input: String
while (true) {
idx = 0
input = readLine()
if (input == "0") break
try {
repeat(input.toInt()) {
val text = readLine()
var temp = text.indexOf(' ', idx)
if (temp == -1) temp = text.length
idx = idx.coerceAtLeast(temp)
}
} catch (_: NumberFormatException) { }
bw.appendLine("${idx + 1}")
}
bw.flush()
bw.close()
}
'백준 > 문제' 카테고리의 다른 글
2257번: 화학식량 (0) | 2024.04.30 |
---|---|
30402번: 감마선을 맞은 컴퓨터 (0) | 2024.04.29 |
15351번: 인생 점수 (0) | 2024.04.29 |
5358번: Football Team (0) | 2024.04.26 |
29766번: DKSH 찾기 (0) | 2024.04.26 |
포스팅이 좋았다면 "좋아요❤️" 또는 "구독👍🏻" 해주세요!