-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path359.cpp
More file actions
100 lines (92 loc) · 1.62 KB
/
Copy path359.cpp
File metadata and controls
100 lines (92 loc) · 1.62 KB
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
#include <iostream>
#include <string>
#include <fstream>
using namespace std;
struct Mem {
int op;
int num;
void process(const string& str) {
op = (str[0] - 48) * 4 + (str[1] - 48) * 2 + str[2] - 48;
num = (str[3] - 48) * 16 + (str[4] - 48) * 8 + (str[5] - 48) * 4 + (str[6] - 48) * 2 + str[7] - 48;
}
};
Mem mem[32];
int acc;
int pc;
void print() {
cout << "-----------\n";
cout << pc << endl;
cout << mem[pc].op << " " << mem[pc].num << endl;
cout << acc / 32 << " " << acc % 32 << endl;
cout << "-----------\n";
}
int main() {
freopen("/Users/xdd44/Documents/Code/359/sample.in", "r", stdin);
string str;
while (cin >> str) {
mem[0].process(str);
for (int i=1;i<32;i++) {
cin >> str;
mem[i].process(str);
}
acc = 0;
pc = 0;
bool done = false;
while (!done) {
switch (mem[pc].op) {
case 0:
mem[mem[pc].num].op = acc / 32;
mem[mem[pc].num].num = acc % 32;
pc++;
break;
case 1:
acc = mem[mem[pc].num].op * 32 + mem[mem[pc].num].num;
pc++;
break;
case 2:
if (acc == 0) {
pc = mem[pc].num;
}
else {
pc++;
}
break;
case 3:
pc++;
break;
case 4:
if (acc == 0) {
acc = 255;
}
else {
acc--;
}
pc++;
break;
case 5:
acc++;
acc %= 256;
pc++;
break;
case 6:
pc = mem[pc].num;
break;
case 7:
done = true;
break;
}
pc %= 32;
}
cout
<< acc / 128
<< (acc % 128) / 64
<< (acc % 64) / 32
<< (acc % 32) / 16
<< (acc % 16) / 8
<< (acc % 8) / 4
<< (acc % 4) / 2
<< acc % 2
<< endl;
}
return 0;
}