1+ import java .io .BufferedReader ;
2+ import java .io .IOException ;
3+ import java .io .InputStreamReader ;
4+ import java .util .Arrays ;
5+ import java .util .StringTokenizer ;
6+
7+ import static java .lang .Integer .parseInt ;
8+
9+ public class BOJ_16926 {
10+
11+ private static int N ; // 세로
12+ private static int M ; // 가로
13+ private static int R ; // 회전수
14+
15+ private static int [][] arr ;
16+
17+ public static void main (String [] args ) throws IOException {
18+ readInput ();
19+ solve ();
20+ }
21+
22+ private static void solve () {
23+ double midN = N / 2.0 ;
24+ double midM = M / 2.0 ;
25+
26+ int [][] temp = new int [N ][M ];
27+ char [][] chrs = new char [N ][M ];
28+
29+ for (int r = 0 ; r < R ; r ++) {
30+
31+ for (int y = 0 ; y < arr .length ; y ++) {
32+ for (int x = 0 ; x < arr [0 ].length ; x ++) {
33+ if (isDown (midM , y , x )) {
34+ temp [y + 1 ][x ] = arr [y ][x ];
35+ // chrs[y][x] = 'v';
36+ } else if (isUp (midM , y , x )) {
37+ temp [y - 1 ][x ] = arr [y ][x ];
38+ // chrs[y][x] = '^';
39+ } else if (isRight (midN , y , x )) {
40+ temp [y ][x + 1 ] = arr [y ][x ];
41+ // chrs[y][x] = '>';
42+ } else if (isLeft (midN , y , x )) {
43+ temp [y ][x - 1 ] = arr [y ][x ];
44+ // chrs[y][x] = '<';
45+ } else {
46+ temp [y ][x ] = arr [y ][x ];
47+ // chrs[y][x] = 'O';
48+ }
49+ }
50+ }
51+
52+ if (r == R - 1 ) break ;
53+
54+ for (int i = 0 ; i < arr .length ; i ++) {
55+ arr [i ] = Arrays .copyOf (temp [i ], temp [i ].length );
56+ }
57+ }
58+
59+ StringBuilder sb = new StringBuilder ();
60+
61+ // for (char[] chr : chrs) {
62+ // for (char c : chr) {
63+ // System.out.print(c + " ");
64+ // }
65+ // System.out.println();
66+ // }
67+
68+ for (int [] row : temp ) {
69+ String line = Arrays .stream (row )
70+ .mapToObj (String ::valueOf )
71+ .reduce ((nested , element ) -> nested + " " + element )
72+ .get ();
73+ sb .append (line );
74+ sb .append ("\n " );
75+ }
76+
77+ System .out .println (sb );
78+
79+
80+ }
81+
82+ private static boolean isDown (double midM , int y , int x ) {
83+
84+ return x < (int ) midM && x <= y && y < N - (x + 1 );
85+ }
86+
87+ private static boolean isUp (double midM , int y , int x ) {
88+ return x >= midM && y >= (M - x ) && y <= N - (M - x );
89+ }
90+
91+ private static boolean isLeft (double midN , int y , int x ) {
92+ return y < midN && x > y && x < (M - y );
93+ }
94+
95+ private static boolean isRight (double midN , int y , int x ) {
96+ return y >= midN && x >= N - (y + 1 ) && x < M - (N - y );
97+ }
98+
99+ private static void readInput () throws IOException {
100+ BufferedReader br = new BufferedReader (new InputStreamReader (System .in ));
101+ StringTokenizer st = new StringTokenizer (br .readLine ());
102+
103+ N = parseInt (st .nextToken ());
104+ M = parseInt (st .nextToken ());
105+ R = parseInt (st .nextToken ());
106+
107+ arr = new int [N ][M ];
108+
109+ for (int y = 0 ; y < N ; y ++) {
110+ st = new StringTokenizer (br .readLine ());
111+
112+ for (int x = 0 ; x < M ; x ++) {
113+ arr [y ][x ] = parseInt (st .nextToken ());
114+ }
115+ }
116+ }
117+ }
118+ /*
119+ 5 5 2
120+ 1 2 3 4 5
121+ 6 7 8 9 10
122+ 11 12 13 14 15
123+ 16 17 18 19 20
124+ 21 22 23 24 25
125+
126+ 3 2 1
127+ 1 2
128+ 6 3
129+ 5 4
130+
131+ 5 3 1
132+ 1 2 3
133+ 4 5 6
134+ 7 8 9
135+ 10 11 12
136+ 13 14 15
137+
138+ */
139+
140+
141+ /*
142+ - down
143+ x < midX && x <= y && y < N - (x + 1)
144+ - up
145+ x > midX && x >= y && y >= (M - x)
146+ - left
147+ y < midN && x > y && x < (M - y)
148+ - right
149+ y > midN && x < y && x >= M - (y + 1)
150+ */
0 commit comments