[파이썬/python] 백준 4949번 : 균형잡힌 세상(🥈3)

while True:
    stack = []
    n = list(input())
    if n == ["."]:
        break
        
    for i in n:
        
        if i == "[" or i =="(":
            stack.append(i)
        else:
            if not stack and i == "]" or not stack and i == ")":
                stack.append(i)
                break
            
            elif i == "]":
                if stack[-1] == "[":
                    stack.pop()
                elif stack[-1] == "(":
                    stack.append(i)
                    break

            elif i == ")":
                if stack[-1] == "(":
                    stack.pop()
                elif stack[-1] == "[":
                    stack.append(i)
                    break
        
    if len(stack) == 0:
        print("yes")
        
    elif len(stack) > 0:
        print("no")

너무 어거지로 풀었나? .. 내일 다시 좋은 풀이법을 찾아보고 정리해야겠다.

comment