😁 빅데이터 문제 풀기 & Study/- BAEKJOON 문제

[10491] Quite a problem / 파이썬 ( 정규표현식 )

또방91 2021. 12. 13. 23:13
728x90

문제 링크: https://www.acmicpc.net/problem/10491

 

10491번: Quite a problem

It gets tiring, looking for all ways in which the word ‘problem’ can be used (and mis-used) in the news media. And yet, that’s been your job for several years: looking through news stories for that word. Wouldn’t it be better if you could automate

www.acmicpc.net


15번의 실패......(런타임에러, 출력초과 범벅)

이유 1) 더이상 입력받는게 없을 경우 while 문에서 except EOFError: break 을 설정하지 않았음

이유 2) 컴파일 설정할때 problem 단어자체가 아닌 .*problem 로 써줘야 함


정답은 ??

1
2
3
4
5
6
7
8
import re
while True:
    try:
        a=input()
        p=re.match('.*problem', a.lower())
        if p: print('yes')
        elseprint('no')
    except EOFError: break
cs

 


💯 풀이 과정

1
2
3
4
5
6
7
8
9
10
11
#성공===================================== 
import re
while True#입력이 반복될 거니까
    try:
        a=input()
        #대소문자 구분하지 않도록 lower()하거나 또는
        #re.match('.*problem', a, re.I)로 대소문자 무시한다.
        p=re.match('.*problem', a.lower())
        if p: print('yes')
        elseprint('no')
    except EOFError: break #입력이 끝나면 break
cs

 


😎오늘의 한줄평: 머나먼 여정이었다... 입력이 없을때 except 꼭 설정해주자!!!

 

 

 

 

728x90