forked from sitz/UVa-Online-Judge
-
Notifications
You must be signed in to change notification settings - Fork 1
/
10033.cpp
99 lines (97 loc) · 1.33 KB
/
10033.cpp
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
#include <bits/stdc++.h>
using namespace std;
int main()
{
int r[11];
int ram[1001];
int cases;
int instruction;
int count;
cin >> cases;
cin.ignore(100, '\n');
cin.ignore(100, '\n');
while (cases--)
{
count = 0;
fill(r, r + 11, 0);
fill(ram, ram + 1001, 0);
while (cin.peek() != '\n' && cin.peek() != -1)
{
cin >> instruction;
cin.ignore(100, '\n');
ram[count] = instruction;
count++;
}
cin.ignore(100, '\n');
int pos = 0;
int command;
int result = 0;
int d, n;
while (true)
{
command = ram[pos];
result++;
if (command == 100)
{
break;
}
d = (command % 100) / 10;
n = command % 10;
switch (command / 100)
{
case 0:
if (r[n] > 0)
{
pos = r[d];
}
else
{
pos++;
}
break;
case 2:
r[d] = n;
pos++;
break;
case 3:
r[d] += n;
r[d] %= 1000;
pos++;
break;
case 4:
r[d] *= n;
r[d] %= 1000;
pos++;
break;
case 5:
r[d] = r[n];
pos++;
break;
case 6:
r[d] += r[n];
r[d] %= 1000;
pos++;
break;
case 7:
r[d] *= r[n];
r[d] %= 1000;
pos++;
break;
case 8:
r[d] = ram[r[n]];
pos++;
break;
case 9:
ram[r[n]] = r[d];
pos++;
break;
}
}
cout << result << endl;
if (cases)
{
cout << endl;
}
}
return 0;
}