DHistory
[Baekjoon] Greedy - 15904 UCPC는 무엇의 약자일까? 본문
문제
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
채점 결과
'Computer Science > Algorithm' 카테고리의 다른 글
[Baekjoon] Greedy - 2828 사과 담기 게임 (0) | 2023.08.14 |
---|---|
[Baekjoon] Greedy - 1417 국회의원 선거 (0) | 2023.08.14 |
[Baekjoon] Greedy - 16435 스네이크버드 (0) | 2023.08.13 |
[Baekjoon] Greedy - 1343 폴리오미노 (0) | 2023.08.11 |
[Baekjoon] Greedy - 14916 거스름돈 (0) | 2023.08.11 |