-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbaek_4949.py
More file actions
44 lines (40 loc) · 776 Bytes
/
baek_4949.py
File metadata and controls
44 lines (40 loc) · 776 Bytes
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
37
38
39
40
41
42
43
44
def filter(txt): # can be improved using regular expression
output = []
for t in txt:
if t == "(" or t == ")" or t == "[" or t == "]":
output.append(t)
return output
result = []
while True:
raw_input = input()
line = filter(raw_input)
if raw_input != ".":
stack = []
err = False
for l in line:
try:
if l == "(" or l == "[":
stack.append(l)
elif l == "]":
if stack[len(stack) - 1] == "[":
stack.pop()
else:
err = True
break
elif l == ")":
if stack[len(stack) - 1] == "(":
stack.pop()
else:
err = True
break
except:
err = True
break
if err == True or len(stack) != 0:
result.append("no")
else:
result.append("yes")
else:
break
for r in result:
print(r)