37 lines
1.1 KiB
Python
Executable File
37 lines
1.1 KiB
Python
Executable File
#!/usr/bin/env python3
|
|
import sys, re
|
|
pattern = re.compile(r"([a-z]+) (inc|dec) ([0-9\-]+) if ([a-z]+) ([><!=]+) ([0-9\-]+)")
|
|
data = [pattern.findall(line.strip())[0] for line in sys.stdin.readlines()]
|
|
values = {}
|
|
def getvar(name):
|
|
try:
|
|
return values[name]
|
|
except KeyError:
|
|
return 0
|
|
|
|
def run_if(variable, operator, value):
|
|
if operator == '==':
|
|
return getvar(variable) == value
|
|
elif operator == '!=':
|
|
return getvar(variable) != value
|
|
elif operator == '>':
|
|
return getvar(variable) > value
|
|
elif operator == '<':
|
|
return getvar(variable) < value
|
|
elif operator == '>=':
|
|
return getvar(variable) >= value
|
|
elif operator == '<=':
|
|
return getvar(variable) <= value
|
|
|
|
max_ever = -9000
|
|
for line in data:
|
|
if run_if(line[3], line[4], int(line[5])):
|
|
if line[1] == 'inc':
|
|
values[line[0]] = getvar(line[0]) + int(line[2])
|
|
elif line[1] == 'dec':
|
|
values[line[0]] = getvar(line[0]) - int(line[2])
|
|
if values[line[0]] > max_ever:
|
|
max_ever = values[line[0]]
|
|
|
|
print(max(values.values()), max_ever)
|