백준
[백준] 15904번: UCPC는 무엇의 약자일까?(파이썬)
초코바나나쉐이크
2024. 10. 19. 01:28
https://www.acmicpc.net/problem/15904
word에 문자열을 입력받고, 반복문을 통해 word를 하나씩 확인하면서 UCPC가 나왔는지 result에 기록한다.
맨 처음에는 U가 입력받았는지만 확인하고, U가 입력받았다면 그 다음 C를 확인하는 식으로 구현하였다.
word = input()
result = [0,0,0,0] #UCPC순
for i in word:
if i == "U":
result[0] = 1
elif i == "C":
if result[0] == 1:
result[1] = 1
if result[2] == 1:
result[3] = 1
elif i == "P":
if result[1] == 1:
result[2] = 1
#print(f'현재 문자:{i}')
#print(f'현재 result:{result}')
if result[0] == 1 and result[1] == 1 and result[2] == 1 and result[3] == 1:
print("I love UCPC", end='')
else:
print("I hate UCPC", end='')