웹찢남

[백준 1013 Contact 문제] PYTHON 본문

백준 Algorithm

[백준 1013 Contact 문제] PYTHON

harry595 2021. 4. 30. 19:17

김동혁 박사님이 정규 표현식을 주셨다. 

re를 통해 그대로 값을 넣어 간단히 해결할 수 있었다.

 

import re

N = int(input())
string= []
for _ in range(N):
    string.append(input())

for i in string:
    p=re.compile('(100+1+|01)+')
    result=p.fullmatch(i)
    if result:
        print('YES')
    else:
        print('NO')

 

fullmatch 란?

Comments