UVA253(骰子涂色)
分别把1.6,2.5,3.4看作底面,有三种变换,自己画个图就很简单了。
写三个变换的函数,枚举所有的变换情况,如果在变换过程中出现与原串相同,就为true。
1 #include <iostream> 2 #include <cstdio> 3 #include <algorithm> 4 #include <cstdlib> 5 #include <cmath> 6 #include <cstring> 7 using namespace std; 8 9 void hchange(char *s) 10 { 11 int t=s[1]; 12 s[1]=s[2]; 13 s[2]=s[4]; 14 s[4]=s[3]; 15 s[3]=t; 16 } 17 void schange1(char *s) 18 { 19 int t=s[0]; 20 s[0]=s[2]; 21 s[2]=s[5]; 22 s[5]=s[3]; 23 s[3]=t; 24 } 25 void schange2(char *s) 26 { 27 int t=s[0]; 28 s[0]=s[1]; 29 s[1]=s[5]; 30 s[5]=s[4]; 31 s[4]=t; 32 } 33 int main() 34 { 35 char s1[20]; 36 char s[7]; 37 char s2[7]; 38 int i,j,k; 39 while(scanf("%s",s1)!=EOF) 40 { 41 for(i=0; i<6; i++) 42 s[i]=s1[i]; 43 s[6]='\0'; 44 for(i=0; i<6; i++) 45 s2[i]=s1[i+6]; 46 s2[6]='\0'; 47 int cnt=0; 48 for(i=1; i<=4; i++) 49 { 50 hchange(s); 51 if(strcmp(s,s2)==0) 52 cnt++; 53 for(j=1; j<=4; j++) 54 { 55 schange1(s); 56 if(strcmp(s,s2)==0) 57 cnt++; 58 for(k=1; k<=4; k++) 59 { 60 schange2(s); 61 if(strcmp(s,s2)==0) 62 cnt++; 63 } 64 } 65 } 66 if(cnt) 67 printf("TRUE\n"); 68 else 69 printf("FALSE\n"); 70 } 71 return 0; 72 }