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°两种路线就行了。只有判断这个情况是否走过比较麻烦,所以我没有实现这个。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值