teratail header banner
teratail header banner
質問するログイン新規登録

質問編集履歴

1

更新

2016/11/13 05:20

投稿

gyro16
gyro16

スコア89

title CHANGED
File without changes
body CHANGED
@@ -147,4 +147,109 @@
147
147
  課題に対してアプローチしたことを記載してください
148
148
 
149
149
  ###補足情報(言語/FW/ツール等のバージョンなど)
150
- より詳細な情報
150
+ より詳細な情報
151
+ '''java
152
+ import java.util.*;
153
+
154
+ public class Main{
155
+ private static final Scanner scan = new Scanner(System.in);
156
+ static boolean flag = false;
157
+
158
+ public static void main(String[] args){
159
+
160
+ int n = scan.nextInt();
161
+ int[] d = new int[6];
162
+ Dice[] dices = new Dice[n];
163
+
164
+ for(int i = 0; i < n; i++){
165
+ for(int j = 0; j < 6; j++){
166
+ d[j] = scan.nextInt();
167
+ }
168
+ dices[i] = new Dice(d);
169
+ }
170
+
171
+ for(int i = 0; i < n - 1; i++){
172
+ for(int j = n - 1; j > i; j--){
173
+ flag = checkSameDice(dices[j], dices[j - 1]);
174
+ if(flag == true)break;
175
+ }
176
+ if(flag == true)break;
177
+ }
178
+ System.out.println(flag? "No" : "Yes");
179
+ }
180
+
181
+ public static boolean checkSameDice(Dice diceA, Dice diceB){
182
+ flag = false;
183
+ for(int i = 0; i < 4; i++){
184
+ for(int j = 0; j < 4; j++){
185
+ flag = Arrays.equals(diceA._d, diceB._d);
186
+ if(flag == true)break;
187
+ diceB.rollEast();
188
+ }
189
+ for(int j = 0; j < 4; j++){
190
+ flag = Arrays.equals(diceA._d, diceB._d);
191
+ if(flag == true)break;
192
+ diceB.rollSouth();
193
+ }
194
+ flag = Arrays.equals(diceA._d, diceB._d);
195
+ if(flag == true)break;
196
+ diceB.rollRight();
197
+ }
198
+ return flag;
199
+ }
200
+ }
201
+
202
+ class Dice{
203
+
204
+ int[] _d = new int[6];
205
+ public static final int
206
+ TOP = 0, SOUTH = 1, EAST = 2,
207
+ WEST = 3, NORTH = 4, BOTTOM = 5; // 定数
208
+
209
+ public Dice(int[] d){ // コンストラクタ
210
+ for(int i = 0; i < 6; i++){
211
+ _d[i] = d[i];
212
+ }
213
+ }
214
+
215
+ public void rollSouth(){
216
+ int tmp = _d[TOP];
217
+ _d[TOP] = _d[NORTH];
218
+ _d[NORTH] = _d[BOTTOM];
219
+ _d[BOTTOM] = _d[SOUTH];
220
+ _d[SOUTH] = tmp;
221
+ }
222
+
223
+ public void rollNorth(){
224
+ int tmp = _d[TOP];
225
+ _d[TOP] = _d[SOUTH];
226
+ _d[SOUTH] = _d[BOTTOM];
227
+ _d[BOTTOM] = _d[NORTH];
228
+ _d[NORTH] = tmp;
229
+ }
230
+
231
+ public void rollEast(){
232
+ int tmp = _d[TOP];
233
+ _d[TOP] = _d[WEST];
234
+ _d[WEST] = _d[BOTTOM];
235
+ _d[BOTTOM] = _d[EAST];
236
+ _d[EAST] = tmp;
237
+ }
238
+
239
+ public void rollWest(){
240
+ int tmp = _d[TOP];
241
+ _d[TOP] = _d[EAST];
242
+ _d[EAST] = _d[BOTTOM];
243
+ _d[BOTTOM] = _d[WEST];
244
+ _d[WEST] = tmp;
245
+ }
246
+
247
+ public void rollRight(){
248
+ int tmp = _d[SOUTH];
249
+ _d[SOUTH] = _d[WEST];
250
+ _d[WEST] = _d[NORTH];
251
+ _d[NORTH] = _d[EAST];
252
+ _d[EAST] = tmp;
253
+ }
254
+ }
255
+ '''