티스토리 뷰

반응형

#. Problem

* The copyright in this matter is in SWEA


#. Resolution Process

  1. Read and understand problem

  2. Redefine the problem + abstract

  3. Create solution plan (select Algorithm, Data structure)

  4. Prove the plan (check performance time and usage memory)

  5. Carry out the plan

  6. Look back on the plan and find a way to improve it


#. Solve


기록해두면 두고두고 볼 것 같아서 기록..


[90도]

00 01 02

10 11 12

20 21 22


20 10 00

21 11 01

22 12 02


00 -> 02

01 -> 12

02 -> 22


10 -> 01 

11 -> 11

12 -> 21


////////////////////////////


[180도]

00 01 02

10 11 12

20 21 22


22 21 20

12 11 10

02 01 00


00 -> 22

01 -> 21

02 -> 20


10 -> 12 

11 -> 11

12 -> 10


/////////////////////////////////


[270도]

00 01 02

10 11 12

20 21 22


02 12 22

01 11 21

00 10 20


00 -> 20

01 -> 10

02 -> 00


10 -> 21

11 -> 11

12 -> 01


#. Code

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
71
72
import java.util.Scanner;
 
public class Solution1961 {
    
    static int N;
    
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        
        int T = sc.nextInt();
        for(int tc=1; tc<=T; tc++) {
            N = sc.nextInt();
            int arr[][] = new int[N][N];
            int arr90[][] = new int[N][N];
            int arr180[][] = new int[N][N];
            int arr270[][] = new int[N][N];
            // Input
            for(int i=0; i<N; i++) {
                for(int j=0; j<N; j++) {
                    arr[i][j] = sc.nextInt();
                }
            }
            
            arr90 = rotation90(arr, arr90);
            arr180 = rotation180(arr, arr180);
            arr270 = rotation270(arr, arr270);
            
            System.out.println("#" + tc);
            for(int i=0; i<N; i++) {
                for(int j=0; j<N; j++
                    System.out.print(arr90[i][j]);
                System.out.print(" ");
                for(int j=0; j<N; j++
                    System.out.print(arr180[i][j]);
                System.out.print(" ");
                for(int j=0; j<N; j++
                    System.out.print(arr270[i][j]);
                System.out.println();
            }
        }
    }
    
    public static int[][] rotation90(int[][] arr, int[][] res) {
        for(int i=0; i<N; i++) {
            for(int j=0; j<N; j++) {
                res[j][N-1-i] = arr[i][j];
            }
        }
        
        return res;
    }
    
    public static int[][] rotation180(int[][] arr, int[][] res) {
        for(int i=0; i<N; i++) {
            for(int j=0; j<N; j++) {
                res[N-1-i][N-1-j] = arr[i][j];
            }
        }
        
        return res;
    }
    
    public static int[][] rotation270(int[][] arr, int[][] res) {
        for(int i=0; i<N; i++) {
            for(int j=0; j<N; j++) {
                res[N-1-j][i] = arr[i][j];
            }
        }
        
        return res;
    }
}
cs

 

#. Other Code

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
/*
reference : 맨
*/
 
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
 
public class Solution{
    public static void main(String[] args)throws IOException{
        BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
        int tn=Integer.parseInt(br.readLine());
        StringTokenizer st=null;
         
        for(int i=1;i<=tn;i++) {
            int N=Integer.parseInt(br.readLine());
            int[][] NbyN=new int [N][N];
            int[][] NbyN1=new int[N][N];
            int[][] NbyN2=new int[N][N];
            int[][] NbyN3=new int[N][N];
             
            for(int j=0;j<N;j++) {
                st=new StringTokenizer(br.readLine());
                for(int k=0;k<N;k++) {
                    NbyN[j][k]=Integer.parseInt(st.nextToken());
                }
            }
             
            for(int j=0;j<N;j++) {
                for(int k=0;k<N;k++) {
                    NbyN1[j][k]=NbyN[N-k-1][j];
                    NbyN2[j][k]=NbyN[N-j-1][N-k-1];
                    NbyN3[j][k]=NbyN[k][N-j-1];
                }
            }
             
            System.out.println("#"+i);
            for(int j=0;j<N;j++) {
                for(int k=0;k<N;k++) {
                    System.out.print(NbyN1[j][k]);
                }
                System.out.print(" ");
                for(int k=0;k<N;k++) {
                    System.out.print(NbyN2[j][k]);
                }
                System.out.print(" ");
                for(int k=0;k<N;k++) {
                    System.out.print(NbyN3[j][k]);
                }
                System.out.println();
            }
        }
     
    }
     
}
cs

 




반응형

'PS > Problem_Solving' 카테고리의 다른 글

[BOJ] 1874.스택 수열(Stack)  (0) 2020.08.02
[BOJ] 14888. 연산자 끼워넣기(순열)  (0) 2020.08.02
[BOJ] 2146. 다리 만들기  (0) 2020.07.06
[BOJ] 2178. 미로 탐색(BFS, DP)  (0) 2020.06.29
[BOJ] 7576. 토마토(BFS)  (0) 2020.06.29
댓글
최근에 올라온 글
최근에 달린 댓글
링크
Total
Today
Yesterday