문제: https://www.acmicpc.net/problem/9012
class Stack(object):
def __init__(self):
self.dt = []
self.lvl = 0
def push(self, n):
self.dt.append(n)
self.lvl += 1
def pop(self):
if self.lvl == 0 : return -1
n = self.dt[-1]
self.dt = self.dt[:-1]
self.lvl -= 1
return n
def size(self):
return self.lvl
def empty(self):
return True if self.lvl == 0 else False
def top(self):
return -1 if data[-1] == [] else data[-1]
def solve(s):
stack = Stack()
for i in s:
if i == '(':
stack.push(i)
elif i == ')':
if stack.empty(): return 'NO'
stack.pop()
return 'YES' if stack.empty() else 'NO'
for _ in range(int(input())):
print(solve(input()))