[백준/9012] 괄호 (파이썬/python)
1️⃣ 문제
문제 링크 : https://www.acmicpc.net/problem/9012
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
댓글남기기