UVa253

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.

picture21

Figure 1.

Since a cube has 6 faces, our machine can paint a face-numbered cube in tex2html_wrap_inline126 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 br, or g. The tex2html_wrap_inline128 character ( tex2html_wrap_inline130 ) 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 tex2html_wrap_inline134 , the one changes into the other.

tex2html_wrap138 tex2html_wrap140

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

题目:

       给出两个正方体各面的染色情况(仅能染红、绿、蓝),判断这两个正方体是否属于同一染色方式(以正方体可以通过翻转变为另一个)。

输入:

       多组数据,每组数据是一长为12的字符串,前6个字符代表第一个正方体各面的染色方式----r红、g绿、b蓝。

输出:

       每组输入输出“对”或者“不对”。

分析:

       注意到,如果正方体的三对对面的染色状况都对应相同的话,两个正方体的染色状况也就相同了。采用string类,将两正方体各自的三对对面染色字母的ASCII码和分别计算出来。如果三对之间形成一一映射即满足同一染色。

 1 #include <cstdio>
 2 #include <iostream>
 3 #include <cstring>
 4 #include <string>
 5 using namespace std;
 6 int main(){
 7     string str;
 8     while(cin >> str){
 9         string a1,a2,a3,b1,b2,b3;
10         a1 = str[0] + str[5];
11         a2 = str[1] + str[4];
12         a3 = str[2] + str[3];
13         b1 = str[6] + str[11];
14         b2 = str[7] + str[10];
15         b3 = str[8] + str[9];
16         if((a1 == b1 || a1 == b2 || a1 == b3)
17            && (a2 == b1 || a2 == b2 || a2 == b3)
18            && (a3 == b1 || a3 == b2 || a3 == b3))
19             if((b1 == a1 || b1 == a2 || b1 == a3)
20                && (b2 == a1 || b2 == a2 || b2 == a3)
21                && (b3 == a1 || b3 == a2 || b3 == a3))
22                 printf("TRUE
");
23             else
24                 printf("FALSE
");
25         else
26             printf("FALSE
");
27     }
28     return 0;
29 }
View Code
原文地址:https://www.cnblogs.com/cyb123456/p/5782331.html