-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCodesquad3
More file actions
195 lines (168 loc) · 5 KB
/
Codesquad3
File metadata and controls
195 lines (168 loc) · 5 KB
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
194
195
package codesquad;
import java.util.*;
public class Codesquad3 {
static char[][] W ={{'W', 'W', 'W'}, {'W', 'W', 'W'}, {'W', 'W', 'W'}};
static char[][] O ={{'O', 'O', 'O'}, {'O', 'O', 'O'}, {'O', 'O', 'O'}};
static char[][] G ={{'G', 'G', 'G'}, {'G', 'G', 'G'}, {'G', 'G', 'G'}};
static char[][] R ={{'R', 'R', 'R'}, {'R', 'R', 'R'}, {'R', 'R', 'R'}};
static char[][] B ={{'B', 'B', 'B'}, {'B', 'B', 'B'}, {'B', 'B', 'B'}};
static char[][] Y ={{'Y', 'Y', 'Y'}, {'Y', 'Y', 'Y'}, {'Y', 'Y', 'Y'}};
public static void F(){
char[] T = {O[0][2], O[1][2], O[2][2]};
for(int j=0; j<3; j++)
O[j][2]= Y[0][j];
for(int j=0; j<3; j++)
Y[0][j] = R[2-j][0];
for(int j=0; j<3; j++)
R[j][0]= W[2][j];
for(int j=0; j<3; j++)
W[2][j] = T[2-j];
}
public static void R() {
char[] T = { W[0][2], W[1][2], W[2][2]};
for(int j=0; j<3; j++)
W[j][2] = G[j][2];
for(int j=0; j<3; j++)
G[j][2]= Y[j][2];
for(int j=0; j<3; j++)
Y[j][2]=B[2-j][0];
for(int j=0; j<3; j++)
B[j][0] = T[2-j];
}
public static void U() {
char [] T = {O[0][0], O[0][1], O[0][2]};
for(int j =0; j<3; j++)
O[0][j] = G[0][j];
for(int j =0; j<3; j++)
G[0][j] = R[0][j];
for(int j =0; j<3; j++)
R[0][j] = B[0][j];
for(int j =0; j<3; j++)
B[0][j]= T[j];
}
public static void L() {
char[] T = {Y[0][0], Y[1][0], Y[2][0]};
for(int j =0; j<3; j++)
Y[j][0] = G[j][0];
for(int j =0; j<3; j++)
G[j][0]= W[j][0];
for(int j =0; j<3; j++)
W[j][0] = B[2-j][2];
for(int j =0; j<3; j++)
B[j][2] = T[2-j];
}
public static void B() {
char [] T = {W[0][0], W[0][1], W[0][2]};
for(int j =0; j<3; j++)
W[0][j]=R[j][2];
for(int j =0; j<3; j++)
R[j][2]=Y[2][2-j];
for(int j =0; j<3; j++)
Y[2][j]=O[j][0];
for(int j =0; j<3; j++)
O[j][0]= T[2-j];
}
public static void D() {
char [] T = {B[2][0], B[2][1], B[2][2]};
for(int j =0; j<3; j++)
B[2][j] = R[2][j];
for(int j =0; j<3; j++)
R[2][j]= G[2][j];
for(int j =0; j<3; j++)
G[2][j]= O[2][j];
for(int j =0; j<3; j++)
O[2][j] = T[j];
}
public static void Random(int n){
Random rd = new Random();
for(int i =0; i< n; i++)
switch(rd.nextInt(11)){
case 0: F(); System.out.print("F\n"); printcube(); break;
case 1: F(); F(); F(); System.out.print("F'\n"); printcube();break;
case 2: R(); System.out.print("R\n"); printcube(); break;
case 3: R(); R(); R(); System.out.print("R'\n"); printcube(); break;
case 4: U(); System.out.print("U\n"); printcube(); break;
case 5: U(); U(); U(); System.out.print("U'\n"); printcube(); break;
case 6: B(); System.out.print("B\n"); printcube(); break;
case 7: B(); B(); B(); System.out.print("B'\n"); printcube(); break;
case 8: L(); System.out.print("L\n"); printcube(); break;
case 9: L(); L(); L(); System.out.print("L'\n"); printcube(); break;
case 10: D(); System.out.print("D\n"); printcube(); break;
case 11: D(); D(); D(); System.out.print("D'\n"); printcube(); break;
}
}
public static void DoSwitch(char c){
switch(c) {
case 'F': F(); break;
case 'R': R(); break;
case 'U': U(); break;
case 'L': L(); break;
case 'B': B(); break;
case 'D': D(); break;
}
}
public static void printrow(char[][] c, int i){
System.out.print(c[i][0]+" "+c[i][1]+" "+c[i][2]+" ");
}
public static void printcube(){
for(int i=0; i<3; i++){
System.out.print(" "); printrow(W, i);
System.out.print("\n");
}
System.out.print("\n");
for(int j=0; j<3; j++){
printrow(O, j); printrow(G, j); printrow(R, j); printrow(B, j);
System.out.print("\n");
}
System.out.println("");
for(int i=0; i<3; i++){
System.out.print(" "); printrow(Y, i);
System.out.print("\n");
}
System.out.print("\n");
}
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
long startTime = System.currentTimeMillis();
printcube();
int times =0;
do {
System.out.print("CUBE> ");
String input = sc.next();
char[] in = input.toCharArray();
int i =0;
while(i<input.length()) {
if((i+1<input.length())&&(in[i+1]=='\u005c\u0027')){
System.out.printf("%c%c\n", in[i], in[i+1]);
DoSwitch(in[i]);
DoSwitch(in[i]);
DoSwitch(in[i]);
printcube();
i += 2;
times ++;
}
else if(in[i]=='Q'){
System.out.printf("%c\n", in[i]);
long estimatedTime = System.currentTimeMillis() - startTime;
long Time= estimatedTime/1000;
System.out.print("경과시간: "+(Time-Time%60)/60 +" : "+(Time%60)+"\n");
System.out.print("조작갯수: "+times+"\n");
System.out.println("이용해주셔서 고맙습니다.");
i++;
}
else if(in[i]=='X'){
System.out.println("몇번 섞으시겠습니까?");
int n = sc.nextInt();
Random(n); break;
}
else{
System.out.printf("%c\n", in[i]);
DoSwitch(in[i]);
printcube();
i++;
times ++;
}
}
}while(true);
}
}