-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path2504.py
More file actions
39 lines (34 loc) · 827 Bytes
/
2504.py
File metadata and controls
39 lines (34 loc) · 827 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
# 괄호의 값
import sys
input = sys.stdin.readline
string = input()
stack = []
calculator = 1
answer = 0
for index in range(len(string)):
if string[index] == '(':
stack.append(string[index])
calculator *= 2
elif string[index] == '[':
stack.append(string[index])
calculator *= 3
elif string[index] == ')':
if not stack or stack[-1] == '[':
answer = 0
break
if string[index-1] == '(':
answer += calculator
stack.pop()
calculator //= 2
elif string[index] == ']':
if not stack or stack[-1] == '(':
answer = 0
break
if string[index-1] == '[':
answer += calculator
stack.pop()
calculator //= 3
if stack:
print(0)
else:
print(answer)