紫书UVA253

模拟的一个水题,然而我花了两天,各种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判断。
posted @ 2018-04-10 20:37  MCQ  阅读(103)  评论(0编辑  收藏  举报