-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path10033.cpp
78 lines (73 loc) · 1.72 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
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
using namespace std;
int main(void)
{
bool halt;
int T;
string ram[1000], op;
int reg[10], len, d, n, cnt, ptr;
scanf("%d\n", &T);
while (T--) {
len = 0;
while (1) {
getline(cin, ram[len]);
if (ram[len] == "")
break;
else
len++;
}
len++;
halt = false;
cnt = 0;
ptr = 0;
memset(reg, 0, sizeof(reg));
while (1) {
op = ram[ptr++];
if (halt) break;
d = int(op[1] - '0');
n = int(op[2] - '0');
cnt++;
switch (op[0]) {
case '1':
halt = !d && !n;
case '2':
reg[d] = n;
break;
case '3':
reg[d] += n;
reg[d] %= 1000;
break;
case '4':
reg[d] *= n;
reg[d] %= 1000;
break;
case '5':
reg[d] = reg[n];
break;
case '6':
reg[d] += reg[n];
reg[d] %= 1000;
break;
case '7':
reg[d] *= reg[n];
reg[d] %= 1000;
break;
case '8':
reg[d] = atoi(ram[reg[n]].c_str());
break;
case '9':
ram[reg[n]] = to_string(reg[d]);
break;
case '0':
if (reg[n]) ptr = reg[d];
break;
}
}
printf("%d\n", cnt);
if (T) printf("\n");
}
return 0;
}