구현하는 문제

배열만 잘 다루면된다. 

모의 역량테스트중 가장 정답률이 높은 문제

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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
import java.io.*;
import java.util.*;
 
public class Solution_모의SW역량테스트_특이한자석 {
    static int arr[][], lot_save[];
    public static void main(String[] args) {
        Scanner sc= new Scanner(System.in);
        int T = sc.nextInt();
        for (int tc = 1; tc <= T; tc++) {
            int n = sc.nextInt();
            arr = new int[4][8];
            lot_save = new int[4];//각 자석의 회전 방향 저장
            for (int i = 0; i < 4; i++) {
                for (int j = 0; j < 8; j++) {
                    arr[i][j] = sc.nextInt();
                }
            }
            for (int i = 0; i < n; i++) {// n번 회전 할거임
                //1번의 2와 2번의 6 확인 
                //2번의 2와 3번의 6 확인
                //3번의 2와 4번의 6 확인
                int lot_num = sc.nextInt()-1;
                lot_save = new int[4];//각 자석의 회전 방향 저장
                Arrays.fill(lot_save, 3);
                lot_save[lot_num] = sc.nextInt();//1 시계 -1 반시계 
                
                if(lot_num == 0) {
                    zero();
                    fir();
                    sec();
                    thi();
                }
                
                if(lot_num == 1) {
                    fir();
                    zero();
                    sec();
                    thi();
                }
                
                if(lot_num == 2) {
                    sec();
                    thi();
                    fir();
                    zero();
                }
                
                if(lot_num == 3) {
                    thi();
                    sec();
                    fir();
                    zero();
                }
                for (int j = 0; j < 4; j++) {
                    if(lot_save[j]==1) {
                        location(j);
                    }else if(lot_save[j] == -1) {
                        rivers(j);
                    }
                }
            }
            //1 2 4 8
            int ans = 0;
            if(arr[0][0== 1) {
                ans += arr[0][0];
            }
            if(arr[1][0== 1) {
                ans += (arr[1][0]*2);
            }
            if(arr[2][0== 1) {
                ans += (arr[2][0]*4);
            }
            if(arr[3][0== 1) {
                ans += (arr[3][0]* 8);
            }
            System.out.println("#"+tc+" "+ans);
        }//tc 끝
    }//main 끝
    static void zero() {
        if(lot_save[1== 3 && arr[0][2== arr[1][6]) {//같으면 1은 가만히
            lot_save[1= 0;
            
        }else {// 다르면 1은 
            if(lot_save[1== 3 &&lot_save[0== 1) {
                lot_save[1= -1;
            }else if(lot_save[1== 3 &&lot_save[0== -1) {
                lot_save[1= 1;
            }else if(lot_save[1== 3 &&lot_save[0== 0) {
                lot_save[1= 0;
            }
        }
        
    }
    static void fir() {
        if(lot_save[2== 3 &&arr[1][2== arr[2][6]) {
            lot_save[2= 0;
        }else {
            if(lot_save[2== 3 &&lot_save[1== 1) {
                lot_save[2= -1;
            }else if(lot_save[2== 3 &&lot_save[1== -1) {
                lot_save[2= 1;
            }else if(lot_save[2== 3 &&lot_save[1== 0) {
                lot_save[2= 0;
            }
            
        }
        if(lot_save[0== 3 &&arr[1][6== arr[0][2]) {
            lot_save[0= 0;
        }else {
            if(lot_save[0== 3 &&lot_save[1== 1) {
                lot_save[0= -1;
            }else if(lot_save[0== 3 &&lot_save[1== -1) {
                lot_save[0= 1;
            }else if(lot_save[0== 3 &&lot_save[1== 0) {
                lot_save[0= 0;
            }
            
        }
    }
    static void sec() {
        if(lot_save[3== 3 &&arr[2][2== arr[3][6]) {
            lot_save[3= 0;
        }else {
            if(lot_save[3== 3 &&lot_save[2== 1) {
                lot_save[3= -1;
            }else if(lot_save[3== 3 &&lot_save[2== -1) {
                lot_save[3= 1;
            }else if(lot_save[3== 3 &&lot_save[2== 0) {
                lot_save[3= 0;
            }
            
        }
        if(lot_save[1== 3 &&arr[2][6== arr[1][2]) {
            lot_save[1= 0;
        }else {
            if(lot_save[1== 3 &&lot_save[2== 1) {
                lot_save[1= -1;
            }else if(lot_save[1== 3 &&lot_save[2== -1) {
                lot_save[1= 1;
            }else if(lot_save[1== 3 &&lot_save[2== 0) {
                lot_save[1= 0;
            }
            
        }
        
    }
    static void thi() {
        if(lot_save[2== 3 &&arr[3][6== arr[2][2]) {
            lot_save[2= 0;
        }else {
            if(lot_save[2== 3 &&lot_save[3== 1) {
                lot_save[2= -1;
            }else if(lot_save[2== 3 &&lot_save[3== -1) {
                lot_save[2= 1;
            }else if(lot_save[2== 3 &&lot_save[3== 0) {
                lot_save[2= 0;
            }
            
        }
        
    }
    
    static void location(int idx) {//시계 방향
        int temp = arr[idx][0];
        arr[idx][0= arr[idx][7];
        arr[idx][7= arr[idx][6];
        arr[idx][6= arr[idx][5];
        arr[idx][5= arr[idx][4];
        arr[idx][4= arr[idx][3];
        arr[idx][3= arr[idx][2];
        arr[idx][2= arr[idx][1];
        arr[idx][1= temp;
    }
    static void rivers(int idx) {// 반시계 방향
        int temp = arr[idx][0];
        arr[idx][0= arr[idx][1];
        arr[idx][1= arr[idx][2];
        arr[idx][2= arr[idx][3];
        arr[idx][3= arr[idx][4];
        arr[idx][4= arr[idx][5];
        arr[idx][5= arr[idx][6];
        arr[idx][6= arr[idx][7];
        arr[idx][7= temp;
    }
}
 
cs

시뮬이니까 ... 하드 코딩했다.. 

최적화는 개나 줘버렸다 ㅎㅎㅎ......