Skip to content

Commit 2eda1f2

Browse files
committed
refactor: 로봇 문제 switch-case → 배열 변경
1 parent 5bfde5d commit 2eda1f2

File tree

1 file changed

+4
-22
lines changed

1 file changed

+4
-22
lines changed

src/week03/geun0/BOJ_1726.java

Lines changed: 4 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ public class BOJ_1726 {
2020
static boolean[][][] visit;
2121
static int[] dx = {0, 0, 1, -1}; //동서남북
2222
static int[] dy = {1, -1, 0, 0}; //동서남북
23+
static int[] turnLeft = {3, 2, 0, 1};
24+
static int[] turnRight = {2, 3, 1, 0};
2325

2426
public static void main(String[] args) throws IOException {
2527
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
@@ -91,38 +93,18 @@ private static void bfs(int sx, int sy, int sdir, int ex, int ey, int edir) {
9193
}
9294

9395
//명령 2 - 왼쪽 90도 회전
94-
int left = turnLeft(dir);
96+
int left = turnLeft[dir];
9597
if (!visit[x][y][left]) {
9698
visit[x][y][left] = true;
9799
qu.offer(new int[]{x, y, left, count + 1});
98100
}
99101

100102
//명령 2 - 오른쪽 90도 회전
101-
int right = turnRight(dir);
103+
int right = turnRight[dir];
102104
if (!visit[x][y][right]) {
103105
visit[x][y][right] = true;
104106
qu.offer(new int[]{x, y, right, count + 1});
105107
}
106108
}
107109
}
108-
109-
private static int turnLeft(int dir) {
110-
switch (dir) {
111-
case 0: return 3;
112-
case 1: return 2;
113-
case 2: return 0;
114-
case 3: return 1;
115-
}
116-
return -1;
117-
}
118-
119-
private static int turnRight(int dir) {
120-
switch (dir) {
121-
case 0: return 2;
122-
case 1: return 3;
123-
case 2: return 1;
124-
case 3: return 0;
125-
}
126-
return -1;
127-
}
128110
}

0 commit comments

Comments
 (0)