Uva 253 - Cube painting

We have a machine for painting cubes. It is supplied with three different colors: blue, red and green. Each face of the cube gets one of these colors. The cube’s faces are numbered as in Figure 1. Since a cube has 6 faces, our machine can paint a face-numbered cube in 36 = 729 different ways. When ignoring the face-numbers, the number of different paintings is much less, because a cube can be rotated. See example below. Wedenoteapaintedcubebyastringof6characters, whereeach character is a ‘b’, ‘r’, or ‘g’. The i-th character (1 ≤ i ≤ 6) from the left gives the color of face i. For example, Figure 2 is a picture of “rbgggr” and Figure 3 corresponds to “rggbgr”. Notice that both cubesarepaintedinthesameway: byrotatingitaroundthevertical axis by 90°, the one changes into the other.

Input

The input of your program is a textfile that ends with the standard end-of-file marker. Each line is a stringof12characters. Thefirst6charactersofthisstringaretherepresentationofapaintedcube, 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<bits/stdc++.h>
#define read() freopen("input.txt","r",stdin);
#define write() freopen("output.txt","w",stdout);
using namespace std;
string temp,s1,s2;
int check(string vis){
	char s3[7]="";int d=0;
	for( int i=0; i<6; i++ ){
		int x=vis[i]-'0';
		s3[d++]=s1[x-1];
	}
	if(s2==s3) return 1;
	else return 0;
}
int main() {
	read();write();
	string str[7]={"123456","214365","312564","415263","513462","624351"};
	while(cin>>temp){
		s1=temp.substr(0,6);s2=temp.substr(6,6);
		int flag=0;
		for( int i=0; i<6; i++ ){
			if(check(str[i])==1) { flag=1;break; }
			swap(str[i][1],str[i][4]);swap(str[i][2],str[i][3]);
			if(check(str[i])==1) { flag=1;break;}
			swap(str[i][1],str[i][2]);swap(str[i][1],str[i][3]);swap(str[i][3],str[i][4]);
			if(check(str[i])==1) { flag=1;break; }
			swap(str[i][2],str[i][3]);swap(str[i][1],str[i][4]);
			if(check(str[i])==1) { flag=1;break; }
		}
		if(flag) cout<<"TRUE\n";
		else cout<<"FALSE\n";
		getchar();
	}
    return 0;
}

猜你喜欢

转载自blog.csdn.net/weixin_43323172/article/details/89786451