-
Notifications
You must be signed in to change notification settings - Fork 0
/
10033.cpp
129 lines (126 loc) · 1.79 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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
#include<cstdio>
#include<cstring>
#include<iostream>
using namespace std;
int d,n,i;
int commond[1002];
bool flag;
char s[1002][5];
int reg[11];
int all;
void f1()
{
flag=false;
all++;
}
void f2()
{
int d=s[i][1]-'0',n=s[i][2]-'0';
reg[d]=n;
all++;
}
void f3()
{
int d=s[i][1]-'0',n=s[i][2]-'0';
reg[d]+=n;
reg[d]%=1000;
all++;
}
void f4()
{
int d=s[i][1]-'0',n=s[i][2]-'0';
reg[d]*=n;
reg[d]%=1000;
all++;
}
void f5()
{
int d=s[i][1]-'0';
int ss=s[i][2]-'0';
reg[d]=reg[ss];
all++;
}
void f6()
{
int d=s[i][1]-'0';
int ss=s[i][2]-'0';
reg[d]+=reg[ss];
reg[d]%=1000;
all++;
}
void f7()
{
int d=s[i][1]-'0';
int ss=s[i][2]-'0';
reg[d]*=reg[ss];
reg[d]%=1000;
all++;
}
void f8()
{
int d=s[i][1]-'0';
int a=s[i][2]-'0';
int temp=(s[reg[a]][0]-'0')*100+(s[reg[a]][1]-'0')*10+(s[reg[a]][2]-'0');
reg[d]=temp;
all++;
}
void f9()
{
int ss=s[i][1]-'0';
int a=s[i][2]-'0';
int temp=reg[ss];
sprintf(s[reg[a]],"%.3d",temp);
all++;
}
void f0()
{
int d=s[i][1]-'0';
int ss=s[i][2]-'0';
if (reg[ss]!=0)
i=reg[d]-1;
all++;
}
main()
{
int total;
int lg;
cin>>total;
getchar();
getchar();
while (total--)
{
memset(reg,0,sizeof(reg));
memset(s,'0',sizeof(s));
all=0;
flag=true;
lg=0;
while(cin.get(s[lg++][0]))
{
if (s[lg-1][0]=='\n') {lg--;break;}
cin.get(s[lg-1][1]);
cin.get(s[lg-1][2]);
getchar();
}
for (i=0;i<1000;i++)
{
if (!flag) break;
switch(s[i][0])
{
case '1':f1();break;
case '2':f2();break;
case '3':f3();break;
case '4':f4();break;
case '5':f5();break;
case '6':f6();break;
case '7':f7();break;
case '8':f8();break;
case '9':f9();break;
case '0':f0();break;
default :break;
}
}
cout<<all<<endl;
if (total) putchar('\n');
}
return 0;
}