-
Notifications
You must be signed in to change notification settings - Fork 0
/
fhbzmips.py
61 lines (59 loc) · 1.73 KB
/
fhbzmips.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
50
51
52
53
54
55
56
57
58
59
60
61
'''
Problem link https://www.beecrowd.com.br/judge/en/problems/view/2536
'''
threshold = 1000
def excute():
try:
num_of_lines = int(input())
instructions = []
for _ in range(num_of_lines):
line = input().split()
instructions.append(tuple(line))
max_num_of_operations = num_of_lines * threshold
r = 0
in_ptr = 0
while (max_num_of_operations > 0):
curr = instructions[in_ptr]
if (curr[1] == 'add'):
r += int(curr[2])
r = r % 256
in_ptr += 1
elif (curr[1] == 'sub'):
r -= int(curr[2])
r = r % 256
in_ptr += 1
elif (curr[1] == 'mul'):
r *= int(curr[2])
r = r % 256
in_ptr += 1
elif (curr[1] == 'div'):
r = r // int(curr[2])
r = r % 256
in_ptr += 1
elif (curr[1] == 'and'):
r = r & int(curr[2])
r = r % 256
in_ptr += 1
elif (curr[1] == 'or'):
r = r | int(curr[2])
r = r % 256
in_ptr += 1
elif (curr[1] == 'xor'):
r = r ^ int(curr[2])
r = r % 256
in_ptr += 1
elif (curr[1] == 'gotoif'):
if r >= int(curr[2]):
in_ptr = int(curr[3])-1
else:
in_ptr += 1
else:
print(r)
return 1
max_num_of_operations -= 1
print("execucao infinita")
return 1
except EOFError:
return 0
while excute():
pass