|
| 1 | +package 아더; |
| 2 | + |
| 3 | +import java.io.*; |
| 4 | + |
| 5 | +public class BOJ_16926_배열돌리기 { |
| 6 | + |
| 7 | + static int N, M, R, layer; |
| 8 | + static int[][] adj, dir = {{1, 0}, {0, 1}, {-1, 0}, {0, -1}}; |
| 9 | + |
| 10 | + public static void main(String[] args) { |
| 11 | + try { |
| 12 | + input(); |
| 13 | + solve(); |
| 14 | + print(); |
| 15 | + } catch (IOException e) { |
| 16 | + e.printStackTrace(); |
| 17 | + } |
| 18 | + } |
| 19 | + |
| 20 | + private static void print() { |
| 21 | + for (int i = 0; i < N; i++) { |
| 22 | + for (int j = 0; j < M; j++) { |
| 23 | + System.out.print(adj[i][j] + " "); |
| 24 | + } |
| 25 | + System.out.println(); |
| 26 | + } |
| 27 | + } |
| 28 | + |
| 29 | + private static void solve() { |
| 30 | + rotate(R); |
| 31 | + } |
| 32 | + |
| 33 | + private static void rotate(int rotateNum) { |
| 34 | + for (int i = 0; i < rotateNum; i++) { |
| 35 | + for (int n = 0; n < layer; n++) { |
| 36 | + int tmp = adj[n][n]; |
| 37 | + int edgeCnt = 0; |
| 38 | + int lx = n, ly = n; |
| 39 | + |
| 40 | + while (edgeCnt < 4) { |
| 41 | + int ny = ly + dir[edgeCnt][1]; |
| 42 | + int nx = lx + dir[edgeCnt][0]; |
| 43 | + |
| 44 | + if (ny >= n && nx >= n && ny < N - n && nx < M - n) { |
| 45 | + adj[ly][lx] = adj[ny][nx]; |
| 46 | + ly = ny; |
| 47 | + lx = nx; |
| 48 | + } else { |
| 49 | + edgeCnt++; |
| 50 | + } |
| 51 | + } |
| 52 | + adj[n + 1][n] = tmp; |
| 53 | + } |
| 54 | + } |
| 55 | + } |
| 56 | + |
| 57 | + private static void input() throws IOException { |
| 58 | + //BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); |
| 59 | + BufferedReader br = new BufferedReader(new FileReader(new File("/Users/woo-jinpark/Desktop/Park/05_Test/input/input.txt"))); |
| 60 | + |
| 61 | + String[] split = br.readLine().split(" "); |
| 62 | + N = Integer.parseInt(split[0]); |
| 63 | + M = Integer.parseInt(split[1]); |
| 64 | + R = Integer.parseInt(split[2]); |
| 65 | + layer = Math.min(N, M) / 2; |
| 66 | + adj = new int[N][M]; |
| 67 | + |
| 68 | + for (int i = 0; i < N; i++) { |
| 69 | + split = br.readLine().split(" "); |
| 70 | + for (int j = 0; j < M; j++) { |
| 71 | + adj[i][j] = Integer.parseInt(split[j]); |
| 72 | + } |
| 73 | + } |
| 74 | + } |
| 75 | +} |
0 commit comments