알고리즘/백준
stack - 4949번 균형잡힌 세상
토마토오이
2021. 4. 13. 14:22
pytnon
while True :
line = input().rstrip()
if line == '.' : break
stack = []; flag = True
line_list = list(line)
for txt in line_list :
if txt == '(' or txt =='[' :
stack.append(txt)
elif txt == ']' :
if stack and stack[-1] == '[' :
stack.pop()
else :
flag = False
break
elif txt == ')' :
if stack and stack[-1] == '(' :
stack.pop()
else :
flag = False
break
print('yes' if flag and not(stack) else 'no')