UVA 253 (13.08.06)

 Cube painting 

We have a machine for painting cubes. It is supplied withthree different colors: blue,red and green. Each face of the cube gets oneof these colors. The cube's faces arenumbered as in Figure 1.

 

picture21

 

 

Figure 1.

Since a cube has 6 faces, our machine canpaint a face-numbered cube in tex2html_wrap_inline126 different ways. When ignoring the face-numbers,the number of different paintings ismuch 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 ab, r,or g. The tex2html_wrap_inline128 character (tex2html_wrap_inline130 ) fromthe left gives the color of facei. For example,Figure 2 is a picture of rbgggr and Figure 3corresponds torggbgr. Notice that bothcubes are painted in the same way: byrotating it around the vertical axis by 90tex2html_wrap_inline134 , theone changes into the other.

tex2html_wrap138tex2html_wrap140

Input

The input of your program is a textfile thatends with the standard end-of-file marker.Each line is a string of 12 characters.The first 6 characters of this string are therepresentation of a painted cube, theremaining 6 characters give you the representationof another cube. Your program determines whetherthese two cubes are painted in thesame way, that is, whether by any combinationof rotations one can be turned into theother. (Reflections are not allowed.)

 

Output

The output is a file of boolean.For each line of input, output contains TRUE if thesecond half can be obtained from the firsthalf by rotation as describes above,FALSEotherwise.

 

Sample Input

 

rbgggrrggbgr
rrrbbbrrbbbr
rbgrbgrrrrrg

 

Sample Output

 

TRUE
FALSE
FALSE


题意: 一个如图所示的正方体, 每面标了数字以及印上了某字符

给出按原始顺序读取的(即按数字从小到大读)字符串以及我们需要的目标字符串

通过旋转正方体, 再读取这个正方体上的字符串 判断是否与我们需要的字符串顺序相同~


做法: 设定一份初始的顺序, 我这里是按某面朝上来份的, 数组为rot

而后, 每一种面朝上时, 围绕一根垂直顶面的轴, 都可以旋转四次~(在我的代码中是用for循环四次~)

每次旋转完要判断, 根据标记输出~TRUE or FALSE


AC代码:

 

#include<stdio.h>
#include<string.h>

int rot[6][6] = {{1,2,3,4,5,6}, {2,6,3,4,1,5}, {6,5,3,4,2,1}, {5,1,3,4,6,2}, {3,1,2,5,6,4}, {4,6,2,5,1,3}};

int main() {
    char oringe[7];
    char tmp[7];
    char change[7];
    char str[13];
    int pos;
    while(gets(str) != NULL) {

        int mark = 0;
        for(int i = 0; i < 6; i++)
            oringe[i] = str[i];
        oringe[6] = '\0';
        
        pos = 0;
        for(int i = 6; i < 12; i++)
            change[pos++] = str[i];
        change[pos] = '\0';

        for(int i = 0; i < 6; i++) {
            pos = 0;
            for(int j = 0; j < 6; j++)
                tmp[pos++] = oringe[rot[i][j]-1];
            tmp[pos] = '\0';
            char cht;
            for(int j = 0; j < 4; j++) {
                cht = tmp[1];
                tmp[1] = tmp[2];
                tmp[2] = tmp[4];
                tmp[4] = tmp[3];
                tmp[3] = cht;
                if(strcmp(change, tmp) == 0) {
                    mark = 1;
                    break;
                }
            }
        }

        if(mark)
            printf("TRUE\n");
        else
            printf("FALSE\n");
    }
    return 0;
}

 

 

 

posted @ 2013-08-07 19:18  pangbangb  阅读(235)  评论(0编辑  收藏  举报