这道题的难点在于 如何思考方块的旋转
每个方块不管如何旋转组合最后都只有24种可能。
求出每种可能然后遍历即可。
注意 1与6对,2与5对,3与4对。
而且当某两组(如1,6 跟2,5)固定时,第三组也就固定了,因为有对应关系存在。所以 3*2*2*2*1*1 = 24
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#define ERROR -1
#define OK 0
int res[][6]={
{ 1, 2, 3, 4, 5, 6 },{ 1, 3, 5, 2, 4, 6 },{ 1, 4, 2, 5, 3, 6 },{ 1, 5, 4, 3, 2, 6 },
{ 2, 1, 4, 3, 6, 5 },{ 2, 3, 1, 6, 4, 5 },{ 2, 4, 6, 1, 3, 5 },{ 2, 6, 3, 4, 1, 5 },
{ 3, 1, 2, 5, 6, 4 },{ 3, 2, 6, 1, 5, 4 },{ 3, 5, 1, 6, 2, 4 },{ 3, 6, 5, 2, 1, 4 },
{ 4, 1, 5, 2, 6, 3 },{ 4, 2, 1, 6, 5, 3 },{ 4, 5, 6, 1, 2, 3 },{ 4, 6, 2, 5, 1, 3 },
{ 5, 1, 3, 4, 6, 2 },{ 5, 3, 6, 1, 4, 2 },{ 5, 4, 1, 6, 3, 2 },{ 5, 6, 4, 3, 1, 2 },
{ 6, 2, 4, 3, 5, 1 },{ 6, 3, 2, 5, 4, 1 },{ 6, 4, 5, 2, 3, 1 },{ 6, 5, 3, 4, 2, 1 }
};
int cmpArray(char* a, char* b){
int i;
for(i=0; i< 6; i++){
if(a[i] != b[i])
return -1;
}
return 0;
}
int pcol(char* s){
char s1[6]={0};
char s2[6]={0};
int i,j;
for(i=0; i < 6; i++)
s1[i] = s[i];
for(i=6; i < 12; i++)
s2[i-6] = s[i];
for(i=0;i<24;i++){
char t[6];
for(j=0; j<6; j++){
t[j] = s1[res[i][j]-1];
}
/*printf("%c%c%c%c%c%c\n", t[0],t[1],t[2],t[3],t[4],t[5]);*/
if(cmpArray(t, s2)==0)
return 1;
}
return 0;
}
int main(void){
char colors[12] = {0};
while(scanf("%s", colors) != EOF){
if(pcol(colors))
printf("TRUE\n");
else
printf("FALSE\n");
}
return 0;
}