-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path1063.cpp
89 lines (73 loc) · 2.81 KB
/
1063.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
#include <iostream>
#include <string>
using namespace std;
int main() {
string s_king, s_stone;
cin >> s_king >> s_stone;
int col_king = s_king[0] - 'A',
row_king = s_king[1] - '0' - 1,
col_stone = s_stone[0] - 'A',
row_stone = s_stone[1] - '0' - 1;
int N;
cin >> N;
while (N--) {
string position;
cin >> position;
int next_col_king = col_king, next_row_king = row_king;
int next_col_stone = col_stone, next_row_stone = row_stone;
if (position == "R") {
next_col_king = col_king + 1;
next_col_stone = col_stone + 1;
} else if (position == "L") {
next_col_king = col_king - 1;
next_col_stone = col_stone - 1;
} else if (position == "B") {
next_row_king = row_king - 1;
next_row_stone = row_stone - 1;
} else if (position == "T") {
next_row_king = row_king + 1;
next_row_stone = row_stone + 1;
} else if (position == "RT") {
next_col_king = col_king + 1;
next_row_king = row_king + 1;
next_col_stone = col_stone + 1;
next_row_stone = row_stone + 1;
} else if (position == "LT") {
next_col_king = col_king - 1;
next_row_king = row_king + 1;
next_col_stone = col_stone - 1;
next_row_stone = row_stone + 1;
} else if (position == "RB") {
next_col_king = col_king + 1;
next_row_king = row_king - 1;
next_col_stone = col_stone + 1;
next_row_stone = row_stone - 1;
} else if (position == "LB") {
next_col_king = col_king - 1;
next_row_king = row_king - 1;
next_col_stone = col_stone - 1;
next_row_stone = row_stone - 1;
}
int prev_col_king = col_king, prev_row_king = row_king;
int prev_col_stone = col_stone, prev_row_stone = row_stone;
(void)prev_col_stone, (void)prev_row_stone;
if (next_col_king >= 0 && next_col_king <= 7 && next_row_king >= 0 && next_row_king <= 7) {
col_king = next_col_king;
row_king = next_row_king;
}
if (next_col_stone >= 0 && next_col_stone <= 7 && next_row_stone >= 0 && next_row_stone <= 7) {
if (col_stone == col_king && row_stone == row_king) {
col_stone = next_col_stone;
row_stone = next_row_stone;
}
}
if (col_king == col_stone && row_king == row_stone) {
col_king = prev_col_king;
row_king = prev_row_king;
}
}
cout << ((char)(col_king + 'A')) << ((char)(row_king + '0' + 1));
cout << '\n';
cout << ((char)(col_stone + 'A')) << ((char)(row_stone + '0' + 1));
return 0;
}