d = {')':'(', ']':'['}
while True:
sentence = input()
if sentence == ".":
break
stack = []
for s in sentence:
if s == "(" or s== "[":
stack.append(s)
if s == ')' or s == "]":
if not stack or stack[-1] != d[s]:
print('no')
break
else:
stack.pop()
else:
if stack:
print('no')
else:
print('yes')
스택하면 빼 놓을 수 없는 괄호 문제!