Algorithm/PS

[BOJ/백준] 9771 - Word Searching [python]

chanwoong1 2023. 3. 27. 11:10
728x90

문제 링크

 

9771번: Word Searching

The first line contains a single word to search. A word contains at most 20 characters. The next line and the rest is a text to search for that word. The text can contain up to 100 lines including blank lines. No line exceeds 250 characters. A word cannot

www.acmicpc.net

문제 풀이

EOF가 입력될 때 까지 입력값을 받으며, 입력값 중 특정한 문자가 발견된다면 그 문자가 발견된 횟수를 출력해준다.

정답 코드

s = input()
cnt = 0
try :
    while True :
        lst = input().split()
        for i in lst :
            if s in i : cnt += 1
except :
    print(cnt)
728x90