UVA 253 Cube painting

来源:互联网 发布:淘宝类目搜索怎么填 编辑:程序博客网 时间:2024/04/26 10:26

 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.

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

rbgggrrggbgrrrrbbbrrbbbrrbgrbgrrrrrg

Sample Output

TRUEFALSEFALSE

题意:输入12个字符。,前6个代表第一个骰子,后六个代表第二个骰子。r、b、g分别代表红,蓝,绿。。

要判断第一个骰子和第二个骰子是不是一样的骰子(即骰子是可以旋转的。。旋转后一样的为相同骰子。。


解法:暴力。。骰子的面可以分为3组。如果在第二个骰子能找到3组和第一个骰子一样的两个对立面。。2个骰子肯定是一样的。。。注意:如果一组面。要把找过的面标记掉。防止找下一组面的时候重复。。。

#include<stdio.h>char sb[13];char s1[7];char s2[7];int judge;void in(){int i;for (i = 0; i < 6; i ++)s1[i] = sb[i];for (i = 6; i < 12; i ++)s2[i - 6] = sb[i];}void ju(){int i, j;for (i = 0; i < 3; i ++){judge = 0;for (j = 0; j < 6; j ++){if (s1[i] == s2[j] && s1[5 - i] == s2[5 - j]){s2[j] = s2[5 - j] = '\0';judge = 1;break;}}if (judge == 0)break;}}int main(){while (gets(sb) != NULL){in();ju();if (judge)printf("TRUE\n");elseprintf("FALSE\n");}return 0;}



原创粉丝点击