forked from ndb796/python-for-coding-test
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path1.java
40 lines (33 loc) Β· 1.1 KB
/
1.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
import java.util.*;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
// Nμ μ
λ ₯λ°κΈ°
int n = sc.nextInt();
sc.nextLine(); // λ²νΌ λΉμ°κΈ°
String[] plans = sc.nextLine().split(" ");
int x = 1, y = 1;
// L, R, U, Dμ λ°λ₯Έ μ΄λ λ°©ν₯
int[] dx = {0, 0, -1, 1};
int[] dy = {-1, 1, 0, 0};
char[] moveTypes = {'L', 'R', 'U', 'D'};
// μ΄λ κ³νμ νλμ© νμΈ
for (int i = 0; i < plans.length; i++) {
char plan = plans[i].charAt(0);
// μ΄λ ν μ’ν ꡬνκΈ°
int nx = -1, ny = -1;
for (int j = 0; j < 4; j++) {
if (plan == moveTypes[j]) {
nx = x + dx[j];
ny = y + dy[j];
}
}
// 곡κ°μ λ²μ΄λλ κ²½μ° λ¬΄μ
if (nx < 1 || ny < 1 || nx > n || ny > n) continue;
// μ΄λ μν
x = nx;
y = ny;
}
System.out.println(x + " " + y);
}
}