-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path2504.py
49 lines (48 loc) · 972 Bytes
/
2504.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
39
40
41
42
43
44
45
46
47
48
49
#2504
str = input()
bra = list(str)
stack = []
top = 0
answer = 0
mul = 1
last = ' '
for i in range(len(bra)):
if bra[i] =="("or bra[i] =="{":
stack.append('(')
mul *= 2
top += 1
last = "("
elif bra[i] =="[":
stack.append('[')
mul *= 3
top += 1
last = "["
elif bra[i] ==")" or bra[i] =="}":
if top < 1:
answer = 0
break
if last == "(":
answer += mul
top -= 1
if stack[top] == "[":
answer = 0
break
stack.pop()
mul /= 2
last = ")"
elif bra[i] == "]":
if top < 1:
answer = 0
break
if last == "[":
answer += mul
top -= 1
if stack[top] == "(" or stack[top] == "{":
answer = 0
break
stack.pop()
mul /= 3
last = "]"
if top > 0:
answer = 0
print(int(answer))