2016-08-17 Problem Solving►UVa UVa 253 - Cube painting Contents 1. Problem2. Solution3. Code Problem中文網址 Solution利用翻轉骰子來替換最上面的,總共 6 面。每次以不同的面當最上面時,再旋轉四次側面,去比對有沒有一樣的。 CodeUVa 25312345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182#include<cstdio>char str1[6], str2[6];inline void clockwise()//順時針旋轉{ int temp = str2[4]; str2[4] = str2[2]; str2[2] = str2[1]; str2[1] = str2[3]; str2[3] = temp;}inline void forward()//向前滾{ int temp = str2[5]; str2[5] = str2[4]; str2[4] = str2[0]; str2[0] = str2[1]; str2[1] = temp;}inline void turnRight()//向右翻{ int temp = str2[3]; str2[3] = str2[0]; str2[0] = str2[2]; str2[2] = str2[5]; str2[5] = temp;}inline bool cmp(){ for (int i = 0; i < 6; i++) if (str1[i] != str2[i]) return false; return true;}int main(){ while ((str1[0] = getchar()) != EOF) { int i; for (i = 1; i < 6; i++) str1[i] = getchar(); for (i = 0; i < 6; i++) str2[i] = getchar(); getchar(); bool ok = false; //以不同的 6 個面當最上面,去做4次旋轉 for (int i = 0; i < 4 && !ok; i++) { for (int j = 0; j < 4; j++) { if (cmp()) { ok = true; break; } clockwise(); } forward(); } for (int i = 0; i < 4 && !ok; i++) { for (int j = 0; j < 4; j++) { if (cmp()) { ok = true; break; } clockwise(); } turnRight(); } puts(ok ? "TRUE" : "FALSE"); } return 0;} Newer UVa 763 - Fibinary Numbers Older UVa 167 - The Sultan's Successors