백준: 18698번 The Walking Adam (Python3)
The Walking Adam 성공다국어
2 초 | 512 MB | 163 | 108 | 89 | 66.418% |
문제
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.
예제 입력 1
3
UUUDU
DDD
UU
예제 출력 1
3
0
2
힌트
In the first test case, he falls down after 3 steps.
In the second test case, he falls down before making any steps.
In the third test case, he doesn’t fall down at all.
답안
1
2
3
4
5
|
trials = int(input())
for i in range(trials):
_ = input()
print ( len(_[:_.index("D")]) if "D" in _ else len(_) )
|
cs |
'공부 > 코딩테스트' 카테고리의 다른 글
백준: 18411번 試験 (Exam) (Python3) (0) | 2022.08.07 |
---|---|
백준: 18414번 X に最も近い値 (The Nearest Value) (Python3) (0) | 2022.08.07 |
백준: 19602번 Dog Treats (Python3) (0) | 2022.08.07 |
백준: 19698번 헛간 청약 (Python3) (0) | 2022.08.07 |
백준: 19944번 뉴비의 기준은 뭘까? (Python3) (0) | 2022.08.07 |
댓글