uva 253 Cube painting

一道简单题,把所有情况列举出来进行对比就行了,原来的顶面可能在旋转后出现在六个面任意一个,当顶面固定的时候,以顶面和底面的连线为轴旋转,会出现4中组合,把所有情况都考虑到就行了,我用的是暴力解法。

#include <stdio.h>
#include <string.h>

char color1[8];
char color2[8];

void func()
{
	char temp[8];
	int i;
	bool f;
	char t;

	//分别对比6种情况

	f = false;
	temp[7] = '\0';
	//不旋转
	strcpy(temp+1, color1+1);
	if(temp[1]==color2[1] && temp[6]==color2[6])
	{
		if(!strcmp(temp+1,color2+1))
		{
			f = true; goto end;
		}
		for(i=1; i<=3; i++)
		{
			t=temp[3]; temp[3]=temp[2]; temp[2]=temp[4]; temp[4]=temp[5]; temp[5]=t;
			if(!strcmp(temp+1,color2+1))
			{
				f = true; goto end;
			}
		}
	}

	//向左旋转一次
	temp[1] = color1[4];
	temp[2] = color1[2];
	temp[3] = color1[1];
	temp[4] = color1[6];
	temp[5] = color1[5];
	temp[6] = color1[3];
	if(temp[1]==color2[1] && temp[6]==color2[6])
	{
		if(!strcmp(temp+1,color2+1))
		{
			f = true; goto end;
		}
		for(i=1; i<=3; i++)
		{
			t=temp[3]; temp[3]=temp[2]; temp[2]=temp[4]; temp[4]=temp[5]; temp[5]=t;
			if(!strcmp(temp+1,color2+1))
			{
				f = true; goto end;
			}
		}
	}

	//向左旋转两次
	temp[1] = color1[6];
	temp[2] = color1[2];
	temp[3] = color1[4];
	temp[4] = color1[3];
	temp[5] = color1[5];
	temp[6] = color1[1];
	if(temp[1]==color2[1] && temp[6]==color2[6])
	{
		if(!strcmp(temp+1,color2+1))
		{
			f = true; goto end;
		}
		for(i=1; i<=3; i++)
		{
			t=temp[3]; temp[3]=temp[2]; temp[2]=temp[4]; temp[4]=temp[5]; temp[5]=t;
			if(!strcmp(temp+1,color2+1))
			{
				f = true; goto end;
			}
		}
	}

	//向右旋转一次
	temp[1] = color1[3];
	temp[2] = color1[2];
	temp[3] = color1[6];
	temp[4] = color1[1];
	temp[5] = color1[5];
	temp[6] = color1[4];
	if(temp[1]==color2[1] && temp[6]==color2[6])
	{
		if(!strcmp(temp+1,color2+1))
		{
			f = true; goto end;
		}
		for(i=1; i<=3; i++)
		{
			t=temp[3]; temp[3]=temp[2]; temp[2]=temp[4]; temp[4]=temp[5]; temp[5]=t;
			if(!strcmp(temp+1,color2+1))
			{
				f = true; goto end;
			}
		}
	}

	//向前旋转一次
	temp[1] = color1[5];
	temp[2] = color1[1];
	temp[3] = color1[3];
	temp[4] = color1[4];
	temp[5] = color1[6];
	temp[6] = color1[2];
	if(temp[1]==color2[1] && temp[6]==color2[6])
	{
		if(!strcmp(temp+1,color2+1))
		{
			f = true; goto end;
		}
		for(i=1; i<=3; i++)
		{
			t=temp[3]; temp[3]=temp[2]; temp[2]=temp[4]; temp[4]=temp[5]; temp[5]=t;
			if(!strcmp(temp+1,color2+1))
			{
				f = true; goto end;
			}
		}
	}

	//向后旋转一次
	temp[1] = color1[2];
	temp[2] = color1[6];
	temp[3] = color1[3];
	temp[4] = color1[4];
	temp[5] = color1[1];
	temp[6] = color1[5];
	if(temp[1]==color2[1] && temp[6]==color2[6])
	{
		if(!strcmp(temp+1,color2+1))
		{
			f = true; goto end;
		}
		for(i=1; i<=3; i++)
		{
			t=temp[3]; temp[3]=temp[2]; temp[2]=temp[4]; temp[4]=temp[5]; temp[5]=t;
			if(!strcmp(temp+1,color2+1))
			{
				f = true; goto end;
			}
		}
	}

end: 
	if(f)
		printf("TRUE\n");
	else
		printf("FALSE\n");
}

int main(void)
{
	char buffer[20];

	while(gets(buffer))
	{
		memcpy(color1+1, buffer, 6);
		color1[7] = '\0';
		memcpy(color2+1, buffer+6, 6);
		color2[7] = '\0';
		func();
	}
}


 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值