알고리즘
[백준] 4949번 균형잡힌 세상 python
_Myway
2023. 7. 11. 22:06
3번이나 틀렸다고 나와서 뭐지 했는데 아이패드로 풀어서 예제 복사할때 줄바꿈이 안됐던거였다..
데탑으로 푸니 잘됨
q = []
while True:
s = input()
if s=='.':
break
for i in range(len(s)):
if s[i] == '.':
if len(q) == 0:
print('yes')
else:
print('no')
q = []
continue
if s[i] == '(' or s[i] == ')' or s[i] == '[' or s[i] == ']':
q.append(s[i])
if len(q) > 0:
if s[i] == ')' and q[len(q) - 2] == '(':
q.pop()
q.pop()
if s[i] == ']' and q[len(q) - 2] == '[':
q.pop()
q.pop()