From 149df7a3454c4b49f5acb5f1873ce051ee4c39dd Mon Sep 17 00:00:00 2001 From: JHLEE325 <82587652+JHLEE325@users.noreply.github.com> Date: Tue, 21 Oct 2025 15:14:11 +0900 Subject: [PATCH] =?UTF-8?q?[20251021]=20BOJ=20/=20G4=20/=20=EC=A3=BC?= =?UTF-8?q?=EC=82=AC=EC=9C=84=20=EA=B5=B4=EB=A6=AC=EA=B8=B0=20/=20?= =?UTF-8?q?=EC=9D=B4=EC=A4=80=ED=9D=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...4 \352\265\264\353\246\254\352\270\260.md" | 112 ++++++++++++++++++ 1 file changed, 112 insertions(+) create mode 100644 "JHLEE325/202510/21 BOJ G4 \354\243\274\354\202\254\354\234\204 \352\265\264\353\246\254\352\270\260.md" diff --git "a/JHLEE325/202510/21 BOJ G4 \354\243\274\354\202\254\354\234\204 \352\265\264\353\246\254\352\270\260.md" "b/JHLEE325/202510/21 BOJ G4 \354\243\274\354\202\254\354\234\204 \352\265\264\353\246\254\352\270\260.md" new file mode 100644 index 00000000..ceed967a --- /dev/null +++ "b/JHLEE325/202510/21 BOJ G4 \354\243\274\354\202\254\354\234\204 \352\265\264\353\246\254\352\270\260.md" @@ -0,0 +1,112 @@ +```java +import java.io.*; +import java.util.*; + +public class Main { + + static int n, m, x, y, k; + static int[][] map; + static int[] dx = {0, 0, 0, -1, 1}; // 동 서 북 남 + static int[] dy = {0, 1, -1, 0, 0}; + static int[] dice = {0, 0, 0, 0, 0, 0}; // 상 하 동 서 북 남 + + public static void main(String[] args) throws IOException { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + StringTokenizer st = new StringTokenizer(br.readLine()); + + n = Integer.parseInt(st.nextToken()); + m = Integer.parseInt(st.nextToken()); + x = Integer.parseInt(st.nextToken()); + y = Integer.parseInt(st.nextToken()); + k = Integer.parseInt(st.nextToken()); + + map = new int[n][m]; + + for (int i = 0; i < n; i++) { + st = new StringTokenizer(br.readLine()); + for (int j = 0; j < m; j++) { + map[i][j] = Integer.parseInt(st.nextToken()); + } + } + + st = new StringTokenizer(br.readLine()); + StringBuilder sb = new StringBuilder(); + for (int i = 0; i < k; i++) { + int op = Integer.parseInt(st.nextToken()); + int nx = x + dx[op]; + int ny = y + dy[op]; + + if (nx >= n || nx < 0 || ny >= m || ny < 0) + continue; + + x = nx; + y = ny; + + switch (op) { + case 1: + move_1(); + copy(nx, ny); + sb.append(dice[0]).append("\n"); + break; + case 2: + move_2(); + copy(nx, ny); + sb.append(dice[0]).append("\n"); + break; + case 3: + move_3(); + copy(nx, ny); + sb.append(dice[0]).append("\n"); + break; + case 4: + move_4(); + copy(nx, ny); + sb.append(dice[0]).append("\n"); + break; + } + } + System.out.println(sb.toString()); + } + + static void move_1() { + int temp = dice[0]; + dice[0] = dice[3]; + dice[3] = dice[1]; + dice[1] = dice[2]; + dice[2] = temp; + } + + static void move_2() { + int temp = dice[0]; + dice[0] = dice[2]; + dice[2] = dice[1]; + dice[1] = dice[3]; + dice[3] = temp; + } + + static void move_3() { + int temp = dice[0]; + dice[0] = dice[5]; + dice[5] = dice[1]; + dice[1] = dice[4]; + dice[4] = temp; + } + + static void move_4() { + int temp = dice[0]; + dice[0] = dice[4]; + dice[4] = dice[1]; + dice[1] = dice[5]; + dice[5] = temp; + } + + static void copy(int cx, int cy) { + if (map[cx][cy] == 0) { + map[cx][cy] = dice[1]; + } else { + dice[1] = map[cx][cy]; + map[cx][cy] = 0; + } + } +} +```