|
| 1 | +```java |
| 2 | + |
| 3 | +import java.io.*; |
| 4 | +import java.util.*; |
| 5 | + |
| 6 | +public class Main { |
| 7 | + static int N, M, R; |
| 8 | + static int[][] arr; |
| 9 | + |
| 10 | + public static void main(String[] args) throws IOException { |
| 11 | + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); |
| 12 | + StringTokenizer st = new StringTokenizer(br.readLine()); |
| 13 | + |
| 14 | + N = Integer.parseInt(st.nextToken()); |
| 15 | + M = Integer.parseInt(st.nextToken()); |
| 16 | + R = Integer.parseInt(st.nextToken()); |
| 17 | + |
| 18 | + arr = new int[N][M]; |
| 19 | + for (int i = 0; i < N; i++) { |
| 20 | + st = new StringTokenizer(br.readLine()); |
| 21 | + for (int j = 0; j < M; j++) { |
| 22 | + arr[i][j] = Integer.parseInt(st.nextToken()); |
| 23 | + } |
| 24 | + } |
| 25 | + |
| 26 | + st = new StringTokenizer(br.readLine()); |
| 27 | + for (int i = 0; i < R; i++) { |
| 28 | + int op = Integer.parseInt(st.nextToken()); |
| 29 | + arr = operation(arr, op); |
| 30 | + } |
| 31 | + |
| 32 | + StringBuilder sb = new StringBuilder(); |
| 33 | + for (int i = 0; i < arr.length; i++) { |
| 34 | + for (int j = 0; j < arr[0].length; j++) { |
| 35 | + sb.append(arr[i][j]).append(" "); |
| 36 | + } |
| 37 | + sb.append("\n"); |
| 38 | + } |
| 39 | + System.out.print(sb); |
| 40 | + } |
| 41 | + |
| 42 | + static int[][] operation(int[][] array, int op) { |
| 43 | + switch (op) { |
| 44 | + case 1: return op1(array); |
| 45 | + case 2: return op2(array); |
| 46 | + case 3: return op3(array); |
| 47 | + case 4: return op4(array); |
| 48 | + case 5: return op5(array); |
| 49 | + case 6: return op6(array); |
| 50 | + default: return array; |
| 51 | + } |
| 52 | + } |
| 53 | + |
| 54 | + static int[][] op1(int[][] array) { |
| 55 | + int rows = array.length; |
| 56 | + int cols = array[0].length; |
| 57 | + int[][] result = new int[rows][cols]; |
| 58 | + |
| 59 | + for (int i = 0; i < rows; i++) { |
| 60 | + for (int j = 0; j < cols; j++) { |
| 61 | + result[i][j] = array[rows - 1 - i][j]; |
| 62 | + } |
| 63 | + } |
| 64 | + return result; |
| 65 | + } |
| 66 | + |
| 67 | + static int[][] op2(int[][] array) { |
| 68 | + int rows = array.length; |
| 69 | + int cols = array[0].length; |
| 70 | + int[][] result = new int[rows][cols]; |
| 71 | + |
| 72 | + for (int i = 0; i < rows; i++) { |
| 73 | + for (int j = 0; j < cols; j++) { |
| 74 | + result[i][j] = array[i][cols - 1 - j]; |
| 75 | + } |
| 76 | + } |
| 77 | + return result; |
| 78 | + } |
| 79 | + |
| 80 | + static int[][] op3(int[][] array) { |
| 81 | + int rows = array.length; |
| 82 | + int cols = array[0].length; |
| 83 | + int[][] result = new int[cols][rows]; |
| 84 | + |
| 85 | + for (int i = 0; i < rows; i++) { |
| 86 | + for (int j = 0; j < cols; j++) { |
| 87 | + result[j][rows - 1 - i] = array[i][j]; |
| 88 | + } |
| 89 | + } |
| 90 | + return result; |
| 91 | + } |
| 92 | + |
| 93 | + static int[][] op4(int[][] array) { |
| 94 | + int rows = array.length; |
| 95 | + int cols = array[0].length; |
| 96 | + int[][] result = new int[cols][rows]; |
| 97 | + |
| 98 | + for (int i = 0; i < rows; i++) { |
| 99 | + for (int j = 0; j < cols; j++) { |
| 100 | + result[cols - 1 - j][i] = array[i][j]; |
| 101 | + } |
| 102 | + } |
| 103 | + return result; |
| 104 | + } |
| 105 | + |
| 106 | + static int[][] op5(int[][] array) { |
| 107 | + int rows = array.length; |
| 108 | + int cols = array[0].length; |
| 109 | + int[][] result = new int[rows][cols]; |
| 110 | + |
| 111 | + int halfR = rows / 2; |
| 112 | + int halfC = cols / 2; |
| 113 | + |
| 114 | + for (int i = 0; i < halfR; i++) { |
| 115 | + for (int j = 0; j < halfC; j++) { |
| 116 | + result[i][j + halfC] = array[i][j]; |
| 117 | + } |
| 118 | + } |
| 119 | + |
| 120 | + for (int i = 0; i < halfR; i++) { |
| 121 | + for (int j = halfC; j < cols; j++) { |
| 122 | + result[i + halfR][j] = array[i][j]; |
| 123 | + } |
| 124 | + } |
| 125 | + |
| 126 | + for (int i = halfR; i < rows; i++) { |
| 127 | + for (int j = halfC; j < cols; j++) { |
| 128 | + result[i][j - halfC] = array[i][j]; |
| 129 | + } |
| 130 | + } |
| 131 | + |
| 132 | + for (int i = halfR; i < rows; i++) { |
| 133 | + for (int j = 0; j < halfC; j++) { |
| 134 | + result[i - halfR][j] = array[i][j]; |
| 135 | + } |
| 136 | + } |
| 137 | + |
| 138 | + return result; |
| 139 | + } |
| 140 | + |
| 141 | + static int[][] op6(int[][] array) { |
| 142 | + int rows = array.length; |
| 143 | + int cols = array[0].length; |
| 144 | + int[][] result = new int[rows][cols]; |
| 145 | + |
| 146 | + int halfR = rows / 2; |
| 147 | + int halfC = cols / 2; |
| 148 | + |
| 149 | + for (int i = 0; i < halfR; i++) { |
| 150 | + for (int j = 0; j < halfC; j++) { |
| 151 | + result[i + halfR][j] = array[i][j]; |
| 152 | + } |
| 153 | + } |
| 154 | + |
| 155 | + for (int i = 0; i < halfR; i++) { |
| 156 | + for (int j = halfC; j < cols; j++) { |
| 157 | + result[i][j - halfC] = array[i][j]; |
| 158 | + } |
| 159 | + } |
| 160 | + |
| 161 | + for (int i = halfR; i < rows; i++) { |
| 162 | + for (int j = halfC; j < cols; j++) { |
| 163 | + result[i - halfR][j] = array[i][j]; |
| 164 | + } |
| 165 | + } |
| 166 | + |
| 167 | + for (int i = halfR; i < rows; i++) { |
| 168 | + for (int j = 0; j < halfC; j++) { |
| 169 | + result[i][j + halfC] = array[i][j]; |
| 170 | + } |
| 171 | + } |
| 172 | + |
| 173 | + return result; |
| 174 | + } |
| 175 | +} |
| 176 | +``` |
0 commit comments