여름의 서재
[백준] 4949_균형잡힌 세상 본문
728x90
import sys
def balanced_world(string):
result = []
output = "yes"
for i in string:
if i == '(' or i == '[':
result.append(i)
elif i == ')':
if result and result[-1]=='(':
result.pop()
else:
output = "no"
return output
elif i == ']':
if result and result[-1]=='[':
result.pop()
else:
output = "no"
return output
if result:
output = 'no'
return output
while True:
input_string = sys.stdin.readline().rstrip()
if input_string == '.':
break
print(balanced_world(input_string))
'알고리즘 > BOJ' 카테고리의 다른 글
[백준] 9012_괄호 (0) | 2021.08.12 |
---|---|
[백준] 5567_결혼식 (0) | 2021.08.12 |
[백준] 2630_색종이 만들기 (0) | 2021.08.12 |
[백준] 1992_쿼드트리 (0) | 2021.08.12 |
[백준] 1931_회의실 배정 (0) | 2021.08.12 |
Comments