-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathZOJ1098(AC).cpp
73 lines (67 loc) · 1000 Bytes
/
ZOJ1098(AC).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
#define _CRT_SECURE_NO_WARNINGS
#include <cstdio>
#include <cstdlib>
using namespace std;
int mem[32];
int acc;
int pc;
bool terminate;
int main()
{
int i, j;
char s[100];
int b;
while(true){
for(i = 0; i < 32; ++i){
if(scanf("%s", s) != 1){
break;
}
b = 0;
for(j = 0; j < 8; ++j){
b <<= 1;
b += (s[j] - '0');
}
mem[i] = b;
}
if(i < 32){
break;
}
pc = 0;
acc = 0;
terminate = false;
while(!terminate){
switch((b = mem[pc], pc = (pc + 1) % 32, b >> 5)){
case 0:
mem[b & 0x1F] = acc;
break;
case 1:
acc = mem[b & 0x1F];
break;
case 2:
if(!acc){
pc = b & 0x1F;
}
break;
case 3:
break;
case 4:
acc = (acc + 0xFF) % 0x100;
break;
case 5:
acc = (acc + 0x01) % 0x100;
break;
case 6:
pc = b & 0x1F;
break;
case 7:
terminate = true;
break;
}
}
for(i = 0; i < 8; ++i){
printf("%d", !!(acc & (1 << (7 - i))));
}
printf("\n");
}
return 0;
}