From eef0691eb06bd2cfc148296bcc8ce7b8d0a40c22 Mon Sep 17 00:00:00 2001 From: "WooJin Park(Ader)" Date: Thu, 12 May 2022 00:22:00 +0900 Subject: [PATCH] =?UTF-8?q?add=20:=20BOJ=2016926=20=EB=B0=B0=EC=97=B4?= =?UTF-8?q?=EB=8F=8C=EB=A6=AC=EA=B8=B01=20=ED=92=80=EC=9D=B4=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 1. 배열돌리기1 문제 풀이 추가 end --- ...\353\217\214\353\246\254\352\270\260.java" | 75 +++++++++++++++++++ 1 file changed, 75 insertions(+) create mode 100644 "src/\354\225\204\353\215\224/BOJ_16926_\353\260\260\354\227\264\353\217\214\353\246\254\352\270\260.java" diff --git "a/src/\354\225\204\353\215\224/BOJ_16926_\353\260\260\354\227\264\353\217\214\353\246\254\352\270\260.java" "b/src/\354\225\204\353\215\224/BOJ_16926_\353\260\260\354\227\264\353\217\214\353\246\254\352\270\260.java" new file mode 100644 index 0000000..c4976e5 --- /dev/null +++ "b/src/\354\225\204\353\215\224/BOJ_16926_\353\260\260\354\227\264\353\217\214\353\246\254\352\270\260.java" @@ -0,0 +1,75 @@ +package 아더; + +import java.io.*; + +public class BOJ_16926_배열돌리기 { + + static int N, M, R, layer; + static int[][] adj, dir = {{1, 0}, {0, 1}, {-1, 0}, {0, -1}}; + + public static void main(String[] args) { + try { + input(); + solve(); + print(); + } catch (IOException e) { + e.printStackTrace(); + } + } + + private static void print() { + for (int i = 0; i < N; i++) { + for (int j = 0; j < M; j++) { + System.out.print(adj[i][j] + " "); + } + System.out.println(); + } + } + + private static void solve() { + rotate(R); + } + + private static void rotate(int rotateNum) { + for (int i = 0; i < rotateNum; i++) { + for (int n = 0; n < layer; n++) { + int tmp = adj[n][n]; + int edgeCnt = 0; + int lx = n, ly = n; + + while (edgeCnt < 4) { + int ny = ly + dir[edgeCnt][1]; + int nx = lx + dir[edgeCnt][0]; + + if (ny >= n && nx >= n && ny < N - n && nx < M - n) { + adj[ly][lx] = adj[ny][nx]; + ly = ny; + lx = nx; + } else { + edgeCnt++; + } + } + adj[n + 1][n] = tmp; + } + } + } + + private static void input() throws IOException { + //BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + BufferedReader br = new BufferedReader(new FileReader(new File("/Users/woo-jinpark/Desktop/Park/05_Test/input/input.txt"))); + + String[] split = br.readLine().split(" "); + N = Integer.parseInt(split[0]); + M = Integer.parseInt(split[1]); + R = Integer.parseInt(split[2]); + layer = Math.min(N, M) / 2; + adj = new int[N][M]; + + for (int i = 0; i < N; i++) { + split = br.readLine().split(" "); + for (int j = 0; j < M; j++) { + adj[i][j] = Integer.parseInt(split[j]); + } + } + } +}