骰子涂色(找规律、打卡)
一、题目
输入两个骰子,判断两者是否等价(输入的顺序为:上、前、左、右、后、下)
二、思路
这种的要么当模拟题,模拟骰子的旋转;或者寻找规律,总结出旋转的结果,从而写出尽量简洁的代码
取上面为参考面,有6种情况,每种情况可水平旋转得4种情况,共24种
三、代码
1 #include<stdio.h> 2 #include<iostream> 3 #include<string.h> 4 using namespace std; 5 int base[7][7] = { {0,1,2,3,4,5} ,{1,5,2,3,0,4},{4,0,2,3,5,1},{5,4,2,3,1,0},{3,1,0,5,4,2},{2,1,5,0,4,3} }; 6 char str[20], str1[10], str2[10],str3[10]; 7 8 int main() 9 { 10 while (scanf("%s",str) == 1) 11 { 12 int flag = 0; 13 for (int i = 0; i < 12; i++) 14 { 15 if (i < 6) 16 str1[i] = str[i]; 17 else 18 str2[i % 6] = str[i]; 19 } 20 21 str2[6] = '\0'; 22 for (int i = 0; i < 6; i++) 23 { 24 for (int j = 0; j < 6; j++) 25 str3[j] = str1[base[i][j]]; 26 str3[6] = '\0'; 27 for (int k = 0; k < 4; k++) 28 { 29 char ch = str3[1]; 30 str3[1] = str3[2]; 31 str3[2] = str3[4]; 32 str3[4] = str3[3]; 33 str3[3] = ch; 34 if (strcmp(str3, str2) == 0) 35 { 36 flag = 1; 37 break; 38 } 39 } 40 if (flag) break; 41 } 42 if (flag) 43 printf("TRUE\n"); 44 else 45 printf("FALSE\n"); 46 } 47 return 0; 48 }
个性签名:时间会解决一切