-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathP6568.cpp
67 lines (56 loc) · 1.35 KB
/
P6568.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
#include <iostream>
using namespace std;
int bin_to_dec(int n) {
int result = 0, temp = 1;
while (n) {
if (n % 2) result += temp;
temp *= 2;
n /= 10;
}
return result;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int memory[32] = {};
int adder = 0;
int PC = 0;
int a;
while (cin >> a) {
memory[0] = bin_to_dec(a);
adder = 0;
PC = 0;
for (int i = 1; i < 32; i++) {
cin >> a;
memory[i] = bin_to_dec(a);
}
while (1) {
int op = memory[PC] / 32;
int x = memory[PC] % 32;
PC = (PC + 1) % 32;
if (op == 0) {
memory[x] = adder;
} else if (op == 1) {
adder = memory[x];
} else if (op == 2) {
if (adder == 0) {
PC = x;
}
} else if (op == 4) {
adder = (adder + 255) % 256;
} else if (op == 5) {
adder = (adder + 1) % 256;
} else if (op == 6) {
PC = x;
} else if (op == 7) {
break;
}
}
for (int i = 7; i >= 0; i--) {
cout << ((adder >> i) & 1);
}
cout << "\n";
}
return 0;
}