题意:判断前半个字符串是否通过旋转能够得到后半个字符串,根据原文我们可以先写出不同数字作为1号位置的情况,然后就是4种情况的判断
#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
int dir[6][6]={{1,2,3,4,5,6},{2,6,3,4,1,5},{6,5,3,4,2,1},{5,1,3,4,6,2},{3,1,2,5,6,4},{4,6,2,5,1,3}}; //数组下标
char str[20],s1[20],s2[20],tmp[20];
int main()
{
int i,j;
while (scanf("%s",str) != EOF )
{
int flag = 0;
for ( i = 0 ; i < 6 ; i++)
s1[i] = str[i];
for ( i = 0 ; i < 6 ; i++)
s2[i] = str[i+6];
for ( i = 0 ; i < 6 ; i++)
{
for ( j = 0 ; j < 6 ; j++)
tmp[j] = s1[dir[i][j]-1];
for (int k = 0 ; k < 4 ; k++)
{
char tt;
tt = tmp[1];
tmp[1] = tmp[2];
tmp[2] = tmp[4];
tmp[4] = tmp[3];
tmp[3] = tt;
if (strcmp(tmp,s2)==0)
{
flag = 1;
break;
}
}
if (flag)
break;
}
if(flag)
cout<<"TRUE"<<endl;
else cout<<"FALSE"<<endl;
}
return 0;
}