-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path1063.cpp
75 lines (72 loc) · 1.54 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
// 1063. 킹
// 2019.05.14
// 시뮬레이션
#include<iostream>
#include<string>
using namespace std;
int main()
{
string k, s;
int n;
cin >> k >> s >> n;
pair<int, int> kingPos = { 7 - (k[1] - '1'),k[0] - 'A' }; // 킹의 좌표
pair<int, int> stonePos = { 7 - (s[1] - '1'),s[0] - 'A' }; // 돌의 좌표
for (int i = 0; i < n; i++)
{
string com;
cin >> com;
int x = 0, y = 0;
for (int j = 0; j < com.size(); j++)
{
if (com[j] == 'L')
{
y -= 1;
}
if (com[j] == 'T')
{
x -= 1;
}
if (com[j] == 'B')
{
x += 1;
}
if (com[j] == 'R')
{
y += 1;
}
}
// 킹이 장외일 경우
if (x + kingPos.first < 0 || y + kingPos.second < 0 || x + kingPos.first >= 8 || y + kingPos.second >= 8)
{
continue;
}
// 돌이 있는 곳
else if (x + kingPos.first == stonePos.first && y + kingPos.second == stonePos.second)
{
// 돌을 밀었을때 돌이 장외일 경우
if (stonePos.first + x < 0 || stonePos.second + y < 0 || stonePos.first + x >= 8 || stonePos.second + y >= 8)
{
continue;
}
// 돌을 밀 수 있는 경우
else
{
// 킹 좌표 재설정
kingPos.first = stonePos.first, kingPos.second = stonePos.second;
// 돌 좌표 재설정
stonePos.first += x;
stonePos.second += y;
}
}
// 돌이 없는 곳
else
{
// 킹 좌표 재설정
kingPos.first += x;
kingPos.second += y;
}
}
// 최종 좌표 출력
printf("%c%d\n%c%d", kingPos.second + 'A', 8 - kingPos.first, stonePos.second + 'A', 8 - stonePos.first);
return 0;
}