紫书UVA253

本文介绍了一种通过旋转判断两个立方体是否相同的方法,并提供了一个使用C++实现的具体示例。通过对输入文件中每行的两个立方体进行比较,程序能够确定两者是否可以通过旋转达到一致的状态。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

模拟的一个水题,然而我花了两天,各种WA,最终借鉴了大神的思路和代码AC了。
/*The input of your program is a textfile that ends with the standard end-of-file marker. Each line is a
string of 12 characters. The first 6 characters of this string are the representation of a painted cube, the
remaining 6 characters give you the representation of another cube. Your program determines whether
these two cubes are painted in the same way, that is, whether by any combination of rotations one can
be turned into the other. (Reflections are not allowed.)
Output
The output is a file of boolean. For each line of input, output contains ‘TRUE’ if the second half can be
obtained from the first half by rotation as describes above, ‘FALSE’ otherwise.
Sample Input
rbgggrrggbgr
rrrbbbrrbbbr
rbgrbgrrrrrg
Sample Output
TRUE
FALSE
FALSE*/
#include<iostream>
#include<cstring>
using namespace std;
int dir[][6]={{0,1,2,3,4,5},{1,5,2,3,0,4},{5,4,2,3,1,0},{4,0,2,3,5,1},{2,1,5,0,4,3},{3,1,0,5,4,2}};
int main()
{
	char s[15];
	while(cin>>s)
	{
		char s1[10],s2[10];
		for(int i=0;i<6;i++)
		{
			s1[i]=s[i];
		}
		s1[6]='\0';
		for(int i=6;i<12;i++)
		{
			s2[i-6]=s[i];
		}
		s2[6]='\0';
		int c=0;
		for(int j=0;j<6;j++)
		{
				char temp[7];
				for(int t=0;t<6;t++)
				{
					temp[t]=s1[dir[j][t]];
				}
				temp[6]='\0';
				if(strcmp(s2,temp)==0)
					{
						c=1;
						break;
					}
				for(int k=0;k<3;k++)
				{
					char tt=temp[1];
					temp[1]=temp[2];
					temp[2]=temp[4];
					temp[4]=temp[3];
					temp[3]=tt;
					if(strcmp(s2,temp)==0)
					{
						c=1;
						break; 
					}
				}
				if(c==1)break;
		}
		if(c==1)
			{
				cout<<"TRUE"<<endl;
			}
		if(c==0)
		{
			cout<<"FALSE"<<endl;
		}
	}
	

}
巧妙的地方在于用strcmp判断。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值