728x90
https://www.acmicpc.net/problem/16926
package a0811;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
import javax.swing.InputMap;
public class Solution_BOJ배열돌리기1_서울_12반_이서영 {
static BufferedReader br ;
static StringTokenizer st;
static int n,m,r;
static int[][]arr;
public static boolean cango(int x, int y) {
return x>=0 && x<n && y>=0 && y<m;
}
public static void rotate(int sx, int sy, int ex, int ey) {
int tmp = arr[sx][sy];
for(int j=sy+1; j<=ey;j++) {
arr[sx][j-1]=arr[sx][j];
}
for(int i=sx+1; i<=ex; i++) {
arr[i-1][ey]=arr[i][ey];
}
for(int j=ey-1;j>=sy; j--) {
arr[ex][j+1]=arr[ex][j];
}
for(int i=ex-1;i>sx; i--) {
arr[i+1][sy] = arr[i][sy];
}
arr[sx+1][sy]=tmp;
}
public static void main(String[] args) throws IOException {
br = new BufferedReader(new InputStreamReader(System.in));
st = new StringTokenizer(br.readLine());
n = Integer.parseInt(st.nextToken());
m = Integer.parseInt(st.nextToken());
r= Integer.parseInt(st.nextToken());
arr = new int[n][m];
for(int i=0; i<n; i++) {
String str = br.readLine();
st = new StringTokenizer(str);
for(int j=0; j<m; j++) {
arr[i][j]=Integer.parseInt(st.nextToken());
}
}
for(int i=0; i<r; i++) {
int sx =0;
int sy =0;
int ex = n-1;
int ey = m-1;
while((sx<ex)&&(sy<ey)) { //시작점은 끝점보다 x,y모두 작아야함 주의!!
rotate(sx,sy,ex,ey);
sx+=1;
sy+=1;
ex-=1;
ey-=1;
}
}
StringBuilder sb = new StringBuilder();
for(int i=0; i<n; i++) {
//sb.append()
for(int j=0; j<m; j++) {
sb.append(arr[i][j]+" ");
}
sb.append("\n");
}
System.out.println(sb);
}
}
'백준 > 구현' 카테고리의 다른 글
배열돌리기시리즈 (0) | 2021.09.29 |
---|---|
배열돌리기3-16935(java) (0) | 2021.08.11 |
색종이- 2563번(java) (0) | 2021.08.11 |
요세푸스 문제 - 1158번 (java) (0) | 2021.08.11 |
스위치 켜고 끄기 (0) | 2021.08.02 |