您的位置:首页 > 大数据 > 人工智能

UVA 253 Cube painting(未通过)

2016-07-17 18:48 676 查看
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.



Figure 1.

Since a cube has 6 faces, our machine can paint a face-numbered cube in  

 different
ways. When ignoring the face-numbers, the number of different paintings is much less, because a cube can be rotated. See example below. We denote a painted cube by a string of 6 characters, where each character is a b, r,
or g. The  

 character ( 

 )
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 cubes are painted in the same way: by rotating it around the
vertical 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 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

//
//  main.cpp
//  UVa 253
//
//  Created by 张嘉韬 on 16/7/17.
//  Copyright © 2016年 张嘉韬. All rights reserved.
//

#include <iostream>
#include <cstring>
#include <cstdio>
using namespace std;
string a,b,c;
int flag;
void print(string t)
{
for(int i=1;i<=6;i++)
{
cout<<t[i];
}
cout<<endl;
}
string fun1(int n,string temp)
{
for(int i=1;i<=n;i++)
{
char t;
t=temp[4];
temp[4]=temp[1];
temp[1]=temp[3];
temp[3]=temp[6];
temp[6]=t;
}
return temp;
}
string fun2(int n,string temp)
{
for(int i=1;i<=n;i++)
{
char t;
t=temp[2];
temp[2]=temp[1];
temp[1]=temp[5];
temp[5]=temp[6];
temp[6]=t;
}
return temp;
}
string fun3(int n,string temp)
{
for(int i=1;i<=n;i++)
{
char t;
t=temp[2];
temp[2]=temp[4];
temp[4]=temp[5];
temp[5]=temp[3];
temp[3]=t;
}
return temp;
}
int comp(string t1,string t2)
{
for(int i=0;i<=6;i++)
{
if(t1[i]!=t2[i]) return 0;
}
return 1;
}
void dfs(int k,string x)
{
string temp;
for(int i=1;i<=3;i++)
{
if(k==1) temp=fun1(i,x);
else if(k==2) temp=fun2(i,x);
else temp=fun3(i,x);
if(k==3)
{
if(strcmp(temp.c_str(),c.c_str())==0)
{
//                print(temp);
//                print(c);
flag=1;
}
return;
}
else dfs(k+1,temp);
}
}
void getb()
{
b[0]='a';
for(int i=0;i<=5;i++)
{
b[i+1]=a[i];
}
}
void getc()
{
c[0]='a';
for(int i=6;i<=11;i++)
{
c[i-5]=a[i];
}
}
int main(int argc, const char * argv[]) {
//freopen("/Users/zhangjiatao/Documents/暑期训练/input.txt","r",stdin);
while(cin>>a)
{
getb();
getc();
//        cout<<a<<endl;
//        print(b);
//        print(c);
flag=0;
dfs(1,b);
if(flag==0) cout<<"FALSE"<<endl;
else cout<<"TRUE"<<endl;
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: