Computer Science/Algorithm
[Baekjoon] Greedy - 15904 UCPC는 무엇의 약자일까?
ddu0422
2023. 8. 13. 11:30
문제
15904번: UCPC는 무엇의 약자일까?
첫 번째 줄에 알파벳 대소문자, 공백으로 구성된 문자열이 주어진다. 문자열의 길이는 최대 1,000자이다. 문자열의 맨 앞과 맨 끝에 공백이 있는 경우는 없고, 공백이 연속해서 2번 이상 주어지는
www.acmicpc.net
풀이
text = input()
def solution(text):
ucpc = 'UCPC'
index = 0
for alpha in text:
if ucpc[index] == alpha:
index += 1
if index == 4:
break
return 'I love UCPC' if index == 4 else 'I hate UCPC'
print(solution(text))
# input: CCCCCUCPC
# output: I love UCPC