UVa 253 - Cube painting

将色子的各个面作为1号面模拟一遍,并让其旋转四次,比较判断。

#include<stdio.h>
#include<string.h>
#define max 50
//模拟6个序号的面为1面 
int arr[6][6]={{0,1,2,3,4,5},{1,5,2,3,0,4},{2,1,5,0,4,3},{3,1,0,5,4,2},{4,0,2,3,5,1},{5,4,2,3,1,0}};

bool rota(char cube2[], char cube1[])//以1-6为轴旋转90度(左->右)然后将两个色子比较 
{
    char temp;
    for(int i=0; i<4; i++)
    {
        temp = cube2[1];
        cube2[1] = cube2[2];
        cube2[2] = cube2[4];
        cube2[4] = cube2[3];
        cube2[3] = temp;
        if(strcmp(cube2, cube1)==0)
            return true;
    }
    return false;
}

int main()
{
    int judge;
    char cube[max], cube1[max], cube2[max], str[max];
    while(scanf("%s",str)!=EOF)
    {
        judge = 0;
        for(int i=0; i<12; i++)//读取每个色子的颜色情况 
        {
            if(i<6) cube[i] = str[i];
            else cube1[i-6] = str[i];
        }
        for(int i=0; i<6 && judge == 0; i++)
        {
            for(int j=0; j<6; j++)
            {
                cube2[j] = cube[arr[i][j]];
            }
            if(rota(cube2, cube1))
            {
                judge = 1;
                puts("TRUE");
                break;
            }
        }
        if(judge==0)
            puts("FALSE");
    }
    return 0;
}
/*
Sample Input

rbgggrrggbgr
rrrbbbrrbbbr
rbgrbgrrrrrg

Sample Output

TRUE
FALSE
FALSE
*/ 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值