4-4
本题若无思路,用暴力穷举法也可以,但代码过于繁琐,且无锻炼编码思维的作用,因此上网查阅得到思路:只要相对面的三组颜色组合有一一对应的,那么该魔方可以通过旋转变换来得到,具体代码如下:
#include <stdio.h>
int main(void)
{
int c, i, j, flag = 0, temp;
char s1[10], s2[10];
while ((c = getchar()) != EOF) {
s1[1] = c;
for (i = 2; i < 7; i++)
s1[i] = getchar();
for (i = 1; i < 7; i++)
s2[i] = getchar();
getchar();//读掉换行符
for (i = 1; i < 4; i++) {
temp = (s1[i]-'0') + (s1[7-i]-'0');
for (j = 1; j < 4; j++)
if ((s2[j]-'0') + (s2[7-j]-'0') == temp) {
flag++;
s2[j] = s2[7-j] = '0';
break;
}
}
if (3 == flag) printf("TRUE\n");
else printf("FALSE\n");
flag = 0;
}
return 0;
}