-
Notifications
You must be signed in to change notification settings - Fork 0
/
boj_1063.java
102 lines (89 loc) · 1.84 KB
/
boj_1063.java
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
101
102
package baekjoonA;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
/* TEST CASE
[Input]
A1 A2 5
B
L
LB
RB
LT
-------------
[Output]
A1
A2
*/
public class boj_1063 {
public static void main(String[] args) throws Exception {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st = new StringTokenizer(br.readLine(), " ");
String king = st.nextToken();
int kx = king.charAt(1) - '0';
int ky = king.charAt(0) - 'A';
String stone = st.nextToken();
int sx = stone.charAt(1) - '0';
int sy = stone.charAt(0) - 'A';
int N = Integer.parseInt(st.nextToken());
// 명령 (킹의 이동)
for (int i = 0; i < N; i++) {
st = new StringTokenizer(br.readLine(), "");
String command = st.nextToken();
int nx = 0;
int ny = 0;
switch (command) {
case "R":
nx = 0;
ny = 1;
break;
case "L":
nx = 0;
ny = -1;
break;
case "B":
nx = -1;
ny = 0;
break;
case "T":
nx = 1;
ny = 0;
break;
case "RT":
nx = 1;
ny = 1;
break;
case "LT":
nx = 1;
ny = -1;
break;
case "RB":
nx = -1;
ny = 1;
break;
case "LB":
nx = -1;
ny = -1;
break;
}
int tempX = kx+nx;
int tempY = ky+ny;
if(tempX<1||tempX>8||tempY<0||tempY>7) continue;
if(tempX == sx && tempY == sy) {
tempX = sx+nx;
tempY = sy+ny;
if(tempX<1||tempX>8||tempY<0||tempY>7) continue;
sx = tempX;
sy = tempY;
}
kx+=nx;
ky+=ny;
}
// 킹의 마지막 위치
king = (char)(ky+65)+""+(kx);
System.out.println(king);
// 돌의 마지막 위치
stone = (char)(sy+65)+""+(sx);
System.out.println(stone);
}
}