최대 1 분 소요

1️⃣ 문제

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


FireShot Capture 003 - 9012번_ 괄호 - www acmicpc net


2️⃣ 코드

import sys

num = int(sys.stdin.readline())
while num>0:
    stack=[]
    str = list(sys.stdin.readline())
    for i in str:
        if i=='(':
            stack.append(i)
        elif i==')':
            if stack:
                stack.pop()
            else:
                print("NO")
                break
    else:
        if not stack:
            print('YES')
        else:
            print('NO')
    num-=1

댓글남기기