-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path1063.cpp
More file actions
51 lines (49 loc) · 1.38 KB
/
1063.cpp
File metadata and controls
51 lines (49 loc) · 1.38 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
#include <iostream>
#include <string>
using namespace std;
struct piece {
string pos;
void setPos(string p) { pos = p; }
void move(string op) {
if (op == "R") {
if (pos[0] + 1 <= 'H') pos[0]++;
} else if (op == "L") {
if (pos[0] - 1 >= 'A') pos[0]--;
} else if (op == "B") {
if (pos[1] - 1 >= '1') pos[1]--;
} else if (op == "T") {
if (pos[1] + 1 <= '8') pos[1]++;
} else if (op == "RT") {
if (pos[0] + 1 <= 'H' && pos[1] + 1 <= '8') pos[0]++, pos[1]++;
} else if (op == "LT") {
if (pos[0] - 1 >= 'A' && pos[1] + 1 <= '8') pos[0]--, pos[1]++;
} else if (op == "RB") {
if (pos[0] + 1 <= 'H' && pos[1] - 1 >= '1') pos[0]++, pos[1]--;
} else if (op == "LB") {
if (pos[0] - 1 >= 'A' && pos[1] - 1 >= '1') pos[0]--, pos[1]--;
}
}
};
int main() {
piece king, stone;
string p;
int n;
cin >> p;
king.setPos(p);
cin >> p;
stone.setPos(p);
cin >> n;
for (int i = 0; i < n; i++) {
string op;
string ktmp, stmp;
cin >> op;
ktmp = king.pos;
stmp = stone.pos;
king.move(op);
if (king.pos == stone.pos) {
stone.move(op);
if (stone.pos == stmp) king.pos = ktmp;
}
}
cout << king.pos << "\n" << stone.pos << "\n";
}