728x90
반응형
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
|
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
public class Main {
static int N, M, R;
static int[] map;
public static void main(String[] args) throws NumberFormatException, IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringBuilder sb = new StringBuilder();
StringTokenizer st;
st = new StringTokenizer(br.readLine());
N = Integer.parseInt(st.nextToken());// 행개수
M = Integer.parseInt(st.nextToken());// 열개수
R = Integer.parseInt(st.nextToken());// 회전수
int min = Math.min(N, M) / 2;
int 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());
}
}
for (int i = 0; i < R; i++) {// 회전수 돌리고
for (int r = 0; r < min; r++) {
int tmp = map[r][r];
for (int c = r + 1; c < M - r; c++) {
map[r][c - 1] = map[r][c];
}
for (int c = r + 1; c < N - r; c++) {
map[c - 1][M - 1 - r] = map[c][M - 1 - r];
}
for (int c = M - 2 - r; c >= r; c--)
map[N - 1 - r][c + 1] = map[N - 1 - r][c];
for (int c = N - 2 - r; c >= r; c--) {
map[c + 1][r] = map[c][r];
}
map[r + 1][r] = tmp;
}
}
for (int i = 0; i < N; i++) {
for (int j = 0; j < M; j++) {
sb.append(map[i][j] + " ");
}
sb.append("\n");
}
System.out.println(sb);
}
}
|
cs |
728x90
반응형
'알고리즘 > 백준' 카테고리의 다른 글
[백준]3040_백설 공주와 일곱 난쟁이 (0) | 2022.02.15 |
---|---|
[백준]16935_배열돌리기3 (1) | 2022.02.09 |
백준-10430번-java-나머지 (0) | 2021.06.08 |
백준-10869번-java-사칙연산 (0) | 2021.06.08 |
백준-1008번-java-A/B (0) | 2021.06.08 |