-
Notifications
You must be signed in to change notification settings - Fork 2
/
10033.cpp
72 lines (64 loc) · 1.19 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
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
int ram[1001], r[11];
int Ind;
char Input[100];
int Empty() {
int i;
for(i = 0; Input[i]; i++) {
if(Input[i] == '\n'){
Input[i] = NULL;
break;
}
}
return strlen(Input) == 0;
}
void ReadCase() {
Ind = 0;
while(gets(Input)) {
if(Empty()) break;
ram[Ind++] = atoi(Input);
}
}
void Cal() {
int i ,ip = 0, a, b, c;
for (i=1;;i++){
a = ram[ip]/100;
b = ram[ip]/10%10;
c = ram[ip]%10;
ip++;
if (a == 1) break;
if (a == 2) r[b] = c;
else if (a == 3) r[b] = (r[b]+c)%1000;
else if (a == 4) r[b] = (r[b]*c)%1000;
else if (a == 5) r[b] = r[c];
else if (a == 6) r[b] = (r[b]+r[c])%1000;
else if (a == 7) r[b] = (r[b]*r[c])%1000;
else if (a == 8) r[b] = ram[r[c]];
else if (a == 9) ram[r[c]] = r[b];
else if (a == 0 && r[c] !=0) ip = r[b];
}
printf("%d\n",i);
}
void Free() {
int i;
for( i = 0; i <= 1000; i++)
ram[i] = 0;
for(i = 0; i <= 9; i++)
r[i] = 0;
}
int main() {
int ks;
//freopen("c:\\h.txt","r",stdin);
gets(Input);
ks = atoi(Input);
gets(Input);
while(ks--) {
ReadCase();
Cal();
if(ks) printf("\n");
Free();
}
return 0;
}