백준1013: Contact - 정규표현식 (Python/파이썬)

Hyn·2025년 3월 12일

Algorithm(Py)

목록 보기
24/37

fullmatch : 문자열이 처음부터 끝까지 패턴과 일치하는지 확인
띄어쓰기 잘못해서 공백 들어가지 않도록 조심~

import sys
import re

T = int(input())
p = re.compile('(100+1+|01)+')

for tc in range(T):
    l = sys.stdin.readline().strip()
    if re.fullmatch(p, l):
        print('YES')
    else:
        print('NO')
profile
쪼렙 개발자 하지만 포기하지 않지

0개의 댓글