Uva253 Cube painting

题目: 两个正方体是否等价。

写的代码有点丑…改一下再发一次吧。

#include <bits/stdc++.h>

using namespace std;
char s[20];
char a[10],b[10];
int check()
{
    char rot[10];
    for(int i = 0; i < 6; i++)
    {

        strcpy(rot,b);
        rot[0] = b[i];
        if(i == 0)
            strcpy(rot,b);
        else if(i == 1)
        {
            rot[1] = b[5];
            rot[5] = b[4];
            rot[4] = b[0];

        }
        else if( i == 2)
        {
            rot[1] = b[5];
            rot[2] = b[4];
            rot[3] = b[1];
            rot[5] = b[3];
            rot[4] = b[0];
        }
        else if( i == 3)
        {
            rot[1] = b[5];
            rot[2] = b[1];
            rot[3] = b[4];
            rot[4] = b[0];
            rot[5] = b[2];
        }
        else if( i == 4)
        {
            rot[1] = b[0];
            rot[5] = b[1];
            rot[4] = b[5];
        }
        else
        {
            rot[1] = b[4];
            rot[5] = b[0];
            rot[4] = b[1];
        }
        for(int j = 0; j < 4; j++)
        {
            if(strcmp(a, rot ) == 0)
                return 1;
            int temp = rot[1];
            rot[1] = rot[2];
            rot[2] = rot[4];
            rot[4] = rot[3];
            rot[3] = temp;
        }
    }
    return 0;
}

int main()
{

    while(~scanf("%s",s))
    {
        for(int i = 0; i < 6; i++)
            a[i] = s[i];
        a[6] = '\0';
        for(int i = 6; i <= 12; i++)
            b[i-6] = s[i];
        if(check())
            printf("TRUE\n");
        else
            printf("FALSE\n");
    }
    return 0;
}

改良版本.

#include <bits/stdc++.h>

using namespace std;
char s[20];
char a[10],b[10];
int rote[6][6] = {{0,1,2,3,4,5},{1,5,2,3,0,4},{2,5,4,1,0,3},{3,5,1,4,0,2},{4,0,2,3,5,1},{5,4,2,3,1,0}};
int check()
{
    char rot[10];
    for(int i = 0; i < 6; i++)
    {
        for(int j = 0; j < 6; j++)
            rot[j] = b[rote[i][j]];
        rot[6] = '\0';
        for(int j = 0; j < 4; j++)
        {
            if(strcmp(a, rot ) == 0)
                return 1;
            int temp = rot[1];
            rot[1] = rot[2];
            rot[2] = rot[4];
            rot[4] = rot[3];
            rot[3] = temp;
        }
    }
    return 0;
}

int main()
{

    while(~scanf("%s",s))
    {
        for(int i = 0; i < 6; i++)
            a[i] = s[i];
        a[6] = '\0';
        for(int i = 6; i <= 12; i++)
            b[i-6] = s[i];
        if(check())
            printf("TRUE\n");
        else
            printf("FALSE\n");
    }
    return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值