题意:正方形的每个面可以染r,g,b三种颜色,现在给你两个正方形,问是否着两个正方形可以互相只通过旋转得到。
两个正方形能够互相得到,当且仅当它们三对相对的面都匹配,所以就很好写了。
#include<cstdio>
#include<cstring>
#include<cmath>
using namespace std;
char s[110];
char s1[110];
char s2[110];
int a[4][4];
int b[4][4];
bool ok()
{
for (int i = 1; i <= 3; i++)
for (int j = 1; j <= 3; j++)
if (a[i][j] != b[i][j]) return false;
return true;
}
int main()
{
while (scanf ("%s", s) != EOF)
{
for (int i = 0; i < 6; i++)
{
s1[i] = s[i];
s2[i] = s[i + 6];
}
memset (a , -1 , sizeof (a) );
memset (b , -1 , sizeof (b) );
int t1, t2;
for (int i = 0; i < 3; i++)
{
if (s1[i] == 'r') t1 = 1;
if (s1[i] == 'g') t1 = 2;
if (s1[i] == 'b') t1 = 3;
if (s1[5 - i] == 'r') t2 = 1;
if (s1[5 - i] == 'g') t2 = 2;
if (s1[5 - i] == 'b') t2 = 3;
a[t1][t2]++;
a[t2][t1]++;
}
for (int i = 0; i < 3; i++)
{
if (s2[i] == 'r') t1 = 1;
if (s2[i] == 'g') t1 = 2;
if (s2[i] == 'b') t1 = 3;
if (s2[5 - i] == 'r') t2 = 1;
if (s2[5 - i] == 'g') t2 = 2;
if (s2[5 - i] == 'b') t2 = 3;
b[t1][t2] ++;
b[t2][t1] ++;
}
if (ok() )
printf ("TRUE\n");
else
printf ("FALSE\n");
}
return 0;
}