백준 Python 4949 균형잡힌 세상

Seohyun·2023년 8월 5일

알고리즘

목록 보기
15/36
post-thumbnail

문제 링크


while True:
    
    inp = input()
    if inp == '.':
        break
    
    stack = []
    
    for i in inp:
        
        if i == '(' or i == '[':
            stack.append(i)
        elif i == ')':
            if stack and stack[-1] == '(':
                stack.pop()
            else:
                stack.append(i)
                break
        elif i == ']':
            if stack and stack[-1] == '[':
                stack.pop()
            else:
                stack.append(i)
                break
    
    if stack:
        print('no')
    else:
        print('yes')
profile
Hail hamster

0개의 댓글