728x90
5013번: Death Knight Hero
Output the number of battles our hero won, assuming he won each battle where he did not Chains of Ice immediately followed by Death Grip.
www.acmicpc.net
문제 풀이
이 문제는 주어진 입력값에 "C"와 "D"가 연속으로 존재한다면 패배로 간주한다. 승리한 전투의 수를 구하는 문제이다. 문자열을 검사할 때, "C"와 "D"가 연속으로 위치하는지 검사하면 된다.
정답 코드
cnt = 0
for _ in range(int(input())) :
s = input()
win = True
for i in range(1, len(s)) :
if s[i - 1] == "C" and s[i] == "D" : win = False
if win : cnt += 1
print(cnt)
728x90
'Algorithm > PS' 카테고리의 다른 글
[BOJ/백준] 5101 - Sequences [python] (0) | 2023.03.12 |
---|---|
[BOJ/백준] 5073 - 삼각형과 세 변 [python] (0) | 2023.03.12 |
[BOJ/백준] 4922 - Walk Like an Egyptian [python] (0) | 2023.03.12 |
[BOJ/백준] 4909 - Judging Olympia [python] (0) | 2023.03.12 |
[BOJ/백준] 4892 - 숫자 맞추기 게임 [python] (0) | 2023.03.12 |