-
Notifications
You must be signed in to change notification settings - Fork 0
/
4949.py
36 lines (34 loc) · 796 Bytes
/
4949.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import sys
import json
input = sys.stdin.readline
json_string = '''{
"]": "[",
")": "("
}'''
json_object = json.loads(json_string)
while True :
str = input().rstrip()
stack = []
if str == ".":
break
for i in str:
if i == '[' or i == '(':
stack.append(i)
elif i == ']':
a = json_object[i]
if len(stack) != 0 and stack[-1] == a:
stack.pop()
else:
stack.append(')')
break
elif i == ')':
a = json_object[i]
if len(stack) != 0 and stack[-1] == a:
stack.pop()
else:
stack.append(')')
break
if len(stack) == 0:
print('yes')
else:
print('no')