Skip to content

Commit

Permalink
Baekjoon #16926 : 배열 돌리기1
Browse files Browse the repository at this point in the history
Baekjoon #16926 : 배열 돌리기1
Merge pull request #8 from allrightDJ0108/macDev
  • Loading branch information
allrightDJ0108 committed Oct 30, 2023
2 parents 68a0e1f + a5d0ab1 commit c2bd334
Show file tree
Hide file tree
Showing 2 changed files with 80 additions and 0 deletions.
Binary file not shown.
80 changes: 80 additions & 0 deletions CodingTestStudy1.0/src/Implementation/Problem16926.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
package Implementation;

import java.io.*;
import java.util.*;

public class Problem16926 {
static int N, M, R;
static int[][] arr;
static int min;

static int[][] dir = {{0,1}, {1,0}, {0,-1}, {-1,0}}; //상단, 우측, 하단, 좌측 채우기

public static void main (String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer str = new StringTokenizer(br.readLine(), " ");

N = Integer.parseInt(str.nextToken());
M = Integer.parseInt(str.nextToken());
R = Integer.parseInt(str.nextToken());

arr = new int[N][M];

for (int i=0; i<N; i++){
str = new StringTokenizer(br.readLine());
for (int j=0; j<M; j++){
arr[i][j] = Integer.parseInt(str.nextToken());
}
}

min = Math.min(N,M);

for (int i=0; i<R; i++){
rotateFn();
}
printFn();
}

static void rotateFn(){

// 회전시켜야 하는 그룹의 개수 : Math.min(N,M) / 2
for (int t=0; t< (min / 2); t++){
int x = t;
int y = t;

int temp = arr[x][y];
int idx = 0;
while (idx < 4){
int nx = x + dir[idx][0];
int ny = y + dir[idx][1];

//System.out.printf("idx : %d. nx : %d / ny : %d \n", idx, nx, ny);

// 현재 회전시키는 그룹의 범위 내
if(nx < N-t && ny < M-t && nx >= t && ny >= t) {
arr[x][y] = arr[nx][ny];
x = nx;
y = ny;
} else {
idx++;
}
}

arr[t+1][t] = temp;
}

}

static void printFn(){
StringBuilder sb = new StringBuilder();
for (int i=0; i<N; i++){
for (int j=0; j<M; j++){
sb.append(arr[i][j]).append(" ");
}

sb.append("\n");
}

System.out.println(sb);
}
}

0 comments on commit c2bd334

Please sign in to comment.