forked from anythingth2/DataStructure_and_Algorithm_Practice
-
Notifications
You must be signed in to change notification settings - Fork 0
/
lab2_2.py
39 lines (31 loc) · 833 Bytes
/
lab2_2.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
37
38
order = str(input('Enter : '))
LEFT_BRACKET = ('[','{','(')
RIGHT_BRACKET = (']','}',')')
BRACKET = LEFT_BRACKET + RIGHT_BRACKET
left_bracket_stack = []
right_bracket_stack = []
def match(bracket,next_bracket):
if bracket == '[':
return next_bracket == ']'
elif bracket == '(':
return next_bracket == ')'
elif bracket == '{':
return next_bracket == '}'
err = False
for char in order:
if char in BRACKET:
if char in LEFT_BRACKET:
left_bracket_stack.append(char)
else:
bracket = left_bracket_stack.pop()
if match(bracket,char):
pass
else:
err = True
break
if len(left_bracket_stack) != 0:
err = True
if err:
print('MISMATCH')
else:
print('MATCH')