因为题目中描述骰子的方法是给其六个面进行编号,所以一个骰子只有24种情况:每一个号朝上就有6种,而每一个面进行横向旋转便又得到4种,总共有24种:
只需要提取出输入的字符串前6位,把24种情况打到表格里,进行查询即可:
#include<stdio.h>
#include<string.h>
#define MAX 30
int cont = 1;
char str_body[MAX][MAX];
char str_head[MAX][MAX];
const int head[6][MAX]= {{1,2,3,4,5,6},{2,6,3,4,1,5},{3,2,6,1,5,4},{4,2,1,6,5,3},{5,1,3,4,6,2},{6,2,4,3,5,1}};
const int head2[6][MAX] = {{1,2,3,4,5,6},{1,3,5,2,4,6},{1,5,4,3,2,6},{1,4,2,5,3,6}};
void go(char a[])
{
int i,j;
for (i = 0; i < 6; i++)
for (j = 0; j < 6; j++)
{
int num = head[i][j] - 1;
str_head[i][j] = a[num];
}
}
void body()
{
int i,j,cont = 0,h;
for (i = 0; i < 6; i++)
{
for (j = 0; j < 4; j++)
{
for (h = 0; h < 6; h++)
{
int num = head2[j][h] - 1;
str_body[cont][h] = str_head[i][num];
}
cont++;
}
}
}
int main()
{
char str[MAX];
char s[MAX];
while(~scanf("%s",str))
{
int i;
go(str);
body();
for (i = 0; i < 24; i++)
if (strcmp(str+6,str_body[i]) == 0){printf("TRUE\n");break;}
if (i == 24)printf("FALSE\n");
}
return 0;
}