UVA 253 Cube painting

题意就是给一个正方体涂色,判断两次涂的是不是一样的,能旋转成一样样子就算作一样。

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

我的做法就是把所有等价的情况枚举出来,然后一一比较,没什么说的,看代码吧。

#include <cstdio>
#include <cstring>
#include <algorithm>
#include <iostream>
using namespace std;
char in[10];
char cmp[30][10]={{1,2,3,4,5,6},{1,4,2,5,3,6},{1,3,5,2,4,6},{1,5,4,3,2,6},
                    {2,6,3,4,1,5},{2,4,6,1,3,5},{2,3,1,6,4,5},{2,1,4,3,6,5},
                    {5,1,3,4,6,2},{5,4,1,6,3,2},{5,3,6,1,4,2},{5,6,4,3,1,2},
                    {6,5,3,4,2,1},{6,4,5,2,3,1},{6,3,2,5,4,1},{6,2,4,3,5,1},
                    {3,2,6,1,5,4},{3,1,2,5,6,4},{3,6,5,2,1,4},{3,5,1,6,2,4},
                    {4,2,1,6,5,3},{4,6,2,5,1,3},{4,1,5,2,6,3},{4,5,6,1,2,3}};
char temp[10];
char s[20];
int main()
{
    int flag,i,j;
    while(scanf("%s",s)!=EOF)
    {
        flag=0;
        for(i=0;i<6;i++)
            in[i]=s[i];
        in[i]='\0';
        for(i=0;i<6;i++)
            s[i]=s[i+6];
        s[i]='\0';
//        printf("%s %s\n",in,s);
        for(i=0;i<24;i++)
        {
            for(j=0;j<6;j++)
            {
                temp[j]=s[cmp[i][j]-1];
            }
            temp[j]='\0';
            if(strcmp(temp,in)==0)
                break;
        }
        if(i==24)
            printf("FALSE\n");
        else
            printf("TRUE\n");
    }
    return 0;
}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45

感觉是比较简单了,还有个办法是让程序来翻骰子,只写出侧面一个方向转90°和垂直方向转90°两种路线就行了。只有判断这个情况是否走过比较麻烦,所以我没有实现这个。

猜你喜欢

转载自blog.csdn.net/qq_39027601/article/details/80075685