본문 바로가기

알고리즘 문제풀이

UCPC는 무엇의 약자일까? (백준 15904)

입력받은 문자열의 앞에서부터 찾고자 하는 문자를 탐색해 나가면 된다. 

import sys 
input = sys.stdin.readline 
string =input().rstrip()
# pr
i,j = 0,0
check = 'UCPC'
ans = ''
while True :
    if i >=len(string):
        print("I hate UCPC") 
        exit() 
    else :
        if string[i] == check[j]:
            ans += check[j]
            j+= 1 
            i+= 1 
        else : 
            i+= 1 
    
    if ans == check :
        print("I love UCPC")
        exit()

'알고리즘 문제풀이' 카테고리의 다른 글

Bronze Cow Party(백준 6248)  (0) 2023.08.25
소가 길을 건너간 이유7 (백준14461)  (0) 2023.08.25
방탈출(백준 23743)  (0) 2023.08.22
복제 로봇(백준 1944)  (0) 2023.08.21
물대기(백준 1368)  (0) 2023.08.21