[백준 4949][Python] 균형잡힌 세상

봉글렛·2023년 4월 19일

백준

목록 보기
54/55

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

문제를 꼼꼼히 읽어야한다.
내가 놓친 부분이 '.' 온점에 관한 처리를 놓쳤다.

  • 입력라인 끝에 '.'이 있는지
  • '.'는 종료되며 종료될때 아무런 출력값도 없어야한다.
    나 같은 경우에는 아래의 반례로 그 문제를 해결했다.

input
[.
.
결과
no

풀이

import sys, re

a = ''
while True:
    a += sys.stdin.readline().rstrip()
    if a == '.':
        break
    elif a[-1] != '.':
        continue
    n = re.sub(r'([a-z,A-Z," "])', '', a)
    result = list()
    for i in n:
        if i in ('[', '('):
            result.append(i)
        elif i in (']', ')'):
            if result:
                if i == ']' and result[-1] == '[':
                    result.pop()
                elif i == ')' and result[-1] == '(':
                    result.pop()
                elif i == ']' and result[-1] == '(':
                    result.append(i)
                    break
                elif i == ')' and result[-1] == '[':
                    result.append(i)
                    break
            else:
                result.append(i)
                break
    if result:
        print('no')
    else:
        print('yes')
    a = ''
profile
어쩌다 개발자 (할 수 있을 때까지!!!!)

0개의 댓글