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')
else: print('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')
else: print('no')
except EOFError: break #입력이 끝나면 break
|
cs |
😎오늘의 한줄평: 머나먼 여정이었다... 입력이 없을때 except 꼭 설정해주자!!!
728x90
'😁 빅데이터 문제 풀기 & Study > - BAEKJOON 문제' 카테고리의 다른 글
[11718] 그대로 출력하기 / 파이썬 (입력없을 때 멈추기) (0) | 2021.12.20 |
---|---|
[15904] UCPC는 무엇의 약자일까? / 파이썬 (정규표현식 6줄이면 끝) (0) | 2021.12.13 |
BRONZE V 난이도 백준 문제 풀기 / 파이썬 (0) | 2021.12.09 |
[14405] 피카츄 / 파이썬 (정규표현식 5줄이면 끝) (0) | 2021.12.08 |
[10173] 니모를 찾아서 / 파이썬 (정규표현식) (0) | 2021.12.08 |