blob: 2ac7c15c4d87117632e0225190897669cd73faea (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
|
from sys import stdin
monkeys = {}
for line in stdin:
out = line[:4]
parts = line[6:].split()
if len(parts) == 1: parts = int(parts[0])
monkeys[out] = parts
def get(k):
m = monkeys[k]
if type(m) != int:
a = get(m[0])
b = get(m[2])
op = m[1]
if op == '+': m = a + b
if op == '-': m = a - b
if op == '*': m = a * b
if op == '/': m = a // b
monkeys[k] = m
return m
print(get('root'))
|