while True:
    # 1. 한 줄을 입력받습니다.
    line = input()
    
    # 2. 마침표(.) 하나만 입력되면 반복문을 종료합니다.
    if line == ".":
        break

    stack = []
    is_balanced = True

    for char in line:
        # 여는 괄호는 일단 보관함(스택)에 넣습니다.
        if char == "(" or char == "[":
            stack.append(char)
        
        # 소괄호 닫기 ')' 를 만났을 때
        elif char == ")":
            if len(stack) > 0 and stack[-1] == "(":
                stack.pop() # 짝이 맞으면 보관함에서 제거
            else:
                is_balanced = False # 짝이 없거나 틀리면 실패
                break
        
        # 대괄호 닫기 ']' 를 만났을 때
        elif char == "]":
            if len(stack) > 0 and stack[-1] == "[":
                stack.pop() # 짝이 맞으면 보관함에서 제거
            else:
                is_balanced = False # 짝이 없거나 틀리면 실패
                break

    # 모든 검사가 끝난 뒤, 보관함(스택)이 텅 비어있어야 진짜 "yes"
    if is_balanced and len(stack) == 0:
        print("yes")
    else:
        print("no")

Embed on website

To embed this project on your website, copy the following code and paste it into your website's HTML: