-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBOJ16926.java
71 lines (52 loc) · 1.61 KB
/
BOJ16926.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
/**
* BOJ 16926번(S1) - 배열 돌리기1
*/
import java.util.Scanner;
public class BOJ16926 {
static int N, M, R;
static int[][] arr;
static int[] dx = { 0, 1, 0, -1 };
static int[] dy = { 1, 0, -1, 0 };
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
N = scan.nextInt(); // NxM 배열
M = scan.nextInt();
R = scan.nextInt(); // 수행해야 하는 회전의 수
arr = new int[N][M];
for (int i=0; i<N; i++)
for (int j=0; j<M; j++)
arr[i][j] = scan.nextInt();
rotateArr();
print(arr);
}
static void rotateArr() {
int cnt = Math.min(N, M) / 2; // 회전해야 할 사각형의 수
for (int i=0; i<R; i++) { // 총 i번 회전
for (int j=0; j<cnt; j++) {
int dir = 0;
int x = j;
int y = j;
int tmp = arr[j][j];
while(dir < 4) {
int nx = x + dx[dir];
int ny = y + dy[dir];
if (nx >= j && nx < N-j && ny >= j && ny < M-j) {
arr[x][y] = arr[nx][ny];
x = nx;
y = ny;
}
else dir++;
}
arr[j+1][j] = tmp;
}
}
}
static void print(int[][] arr) {
for (int i=0; i<N; i++) {
for (int j=0; j<M; j++) {
System.out.print(arr[i][j] + " ");
}
System.out.println();
}
}
}