-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path10-2.py
More file actions
25 lines (24 loc) · 691 Bytes
/
10-2.py
File metadata and controls
25 lines (24 loc) · 691 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
import numpy as np
table = {"(": 1, "[": 2, "{": 3, "<": 4}
pairs = {")": "(", "]": "[", "}": "{", ">": "<"}
scores = []
try:
while True:
chars = list(input())
chunks = []
incomplete = True
for char in chars:
if char in pairs.keys():
if chunks.pop() != pairs[char]: # Corrupted!
incomplete = False
break
else:
chunks.append(char)
if incomplete:
score = 0
while chunks:
score *= 5
score += table[chunks.pop()]
scores.append(score)
except EOFError:
print(int(np.median(scores)))