문제 출처 : https://www.acmicpc.net/problem/18698
언어 : Kotlin
문제 설명 :
Adam has just started learning how to walk (with some help from his brother Omar), and he falls down a lot. In order to balance himself, he raises his hands up in the air (that’s a true story), and once he puts his hands down, he falls.
You are given a string, each character represents a step he walks, if that character is ‘U’ that means his hands are up in this step, if this character is ‘D’ that means his hands are down and he fell down in this step. Your task is to count how many steps he will walk before falling down for the first time.
입력 :
Your program will be tested on one or more test cases. The first line of the input will be a single integer T (1 ≤ T ≤ 100) representing the number of test cases. Followed by T test cases.
Each test case will consist of a single line, containing a non-empty string of at most 100 characters, and each character is either ‘U’ or ‘D’. The characters from left to right represent Adam’s steps in the order he walks them.
출력 :
For each test case print a single line containing the number of steps that Adam will walk before falling down, or the length of the string if he won’t fall down.
제한 사항 :
- 시간 제한 : 2초
- 메모리 제한 : 512MB
입출력 예 :
입력 | 출력 |
3 UUUDU DDD UU |
3 0 2 |
풀이 :
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))
repeat(readLine().toInt()) {
bw.appendLine("${readLine().substringBefore("D").count()}")
bw.flush()
}
bw.close()
}
'백준 > 문제' 카테고리의 다른 글
16499번: 동일한 단어 그룹화하기 (0) | 2024.05.23 |
---|---|
1411번: 비슷한 단어 (0) | 2024.05.23 |
26264번: 빅데이터? 정보보호! (0) | 2024.05.22 |
3111번: 검열 (0) | 2024.05.22 |
11008번: 복붙의 달인 (1) | 2024.05.21 |
포스팅이 좋았다면 "좋아요❤️" 또는 "구독👍🏻" 해주세요!