Uva 253 - Cube painting

博客围绕涂色立方体展开,机器用蓝、红、绿三色涂立方体各面,编号立方体有729种涂法,忽略编号因可旋转涂法减少。程序输入为含两个立方体涂色表示的12字符字符串,输出判断两立方体能否通过旋转变成相同的布尔值。

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

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;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值