-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathHW_49994.java
More file actions
39 lines (33 loc) ยท 1.22 KB
/
HW_49994.java
File metadata and controls
39 lines (33 loc) ยท 1.22 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
// [PG] 49994_๋ฐฉ๋ฌธ ๊ธธ์ด
// ๊ฒ์ ์บ๋ฆญํฐ๊ฐ ์ง๋๊ฐ ๊ธธ ์ค ์บ๋ฆญํฐ๊ฐ ์ฒ์ ๊ฑธ์ด๋ณธ ๊ธธ์ ๊ธธ์ด ๊ตฌํ๊ธฐ
// ์ขํํ๋ฉด(-5, 5) ๋ฒ์ด๋๋ ๋ช
๋ น์ด๋ ๋ฌด์
import java.util.*;
class HW_49994 {
private static boolean isValidMove(int nx, int ny){
return 0 <= nx && nx < 11 && 0 <= ny && ny < 11;
}
private static final HashMap<Character, int[]> location = new HashMap<>();
private static void initLocation(){
location.put('U', new int[]{0, 1});
location.put('D', new int[]{0, -1});
location.put('L', new int[]{-1, 0});
location.put('R', new int[]{1, 0});
}
public int solution(String dirs) { // U(์), D(์๋), L, R
initLocation();
int x = 5, y=5;
HashSet<String> answer = new HashSet<>();
for(int i=0; i<dirs.length(); i++){
int[] offset = location.get(dirs.charAt(i));
int nx = x + offset[0];
int ny = y + offset[1];
if(!isValidMove(nx, ny))
continue;
answer.add(x + " " + y + " " + nx + " " + ny);
answer.add(nx + " " + ny + " " + x + " " + y);
x = nx;
y = ny;
}
return answer.size()/2;
}
}