-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmonth08_3.py
More file actions
39 lines (33 loc) · 809 Bytes
/
month08_3.py
File metadata and controls
39 lines (33 loc) · 809 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
put = list(input())
stack = []
YesOrNo = True
for elem in put:
last = len(stack) - 1
if elem == ')' or elem == '}' or elem == ']':
if len(stack) == 0:
YesOrNo = False
break
elif elem == ')':
if stack[last] != '(':
YesOrNo = False
break
else:
stack.pop()
elif elem == ']':
if stack[last] != '[':
YesOrNo = False
break
else:
stack.pop()
elif elem == '}':
if stack[last] != '{':
YesOrNo = False
break
else:
stack.pop()
else:
stack.append(elem)
if YesOrNo and len(stack) == 0:
print("YES")
else:
print("NO")