现在的位置: 首页 > 综合 > 正文

UVa 253

2018年04月23日 ⁄ 综合 ⁄ 共 1720字 ⁄ 字号 评论关闭

背景:一次编译通过加一次ac就是这么爽!!!!!!

思路:枚举六个面朝上,每种情况旋转4次的所有情况,一共24种,全部枚举出来比较即可!这里比较巧妙的是把每一种情况都写作一个长度为6的字符串,并在第七位加一个'\0

',这样就可以用strcmp来比较了。

#include<stdio.h>
#include<string.h>
int main(void){
    char l[7],r[7],temp[13];
l1: while(~scanf("%s",temp)){
        for(int i=0;i < 12;i++){
            if(i <6) l[i]=temp[i];
            else r[i-6]=temp[i];
        }
        l[6]=r[6]='\0';
        temp[0]=r[0];temp[1]=r[1];temp[5]=r[5];temp[4]=r[4];temp[2]=r[2];temp[3]=r[3];temp[6]='\0';
        for(int i=0;i < 4;i++){
            if(strcmp(l,temp) == 0){
                printf("TRUE\n");
                goto l1;
            }
            char c=temp[1];
            temp[1]=temp[2];temp[2]=temp[4];temp[4]=temp[3];temp[3]=c;
        }
        temp[0]=r[1];temp[1]=r[5];temp[5]=r[4];temp[4]=r[0];temp[2]=r[2];temp[3]=r[3];temp[6]='\0';
        for(int i=0;i < 4;i++){
            if(strcmp(l,temp) == 0){
                printf("TRUE\n");
                goto l1;
            }
            char c=temp[1];
            temp[1]=temp[2];temp[2]=temp[4];temp[4]=temp[3];temp[3]=c;
        }
        temp[0]=r[5];temp[1]=r[4];temp[5]=r[0];temp[4]=r[1];temp[2]=r[2];temp[3]=r[3];temp[6]='\0';
        for(int i=0;i < 4;i++){
            if(strcmp(l,temp) == 0){
                printf("TRUE\n");
                goto l1;
            }
            char c=temp[1];
            temp[1]=temp[2];temp[2]=temp[4];temp[4]=temp[3];temp[3]=c;
        }
        temp[0]=r[4];temp[1]=r[0];temp[5]=r[1];temp[4]=r[5];temp[2]=r[2];temp[3]=r[3];temp[6]='\0';
        for(int i=0;i < 4;i++){
            if(strcmp(l,temp) == 0){
                printf("TRUE\n");
                goto l1;
            }
            char c=temp[1];
            temp[1]=temp[2];temp[2]=temp[4];temp[4]=temp[3];temp[3]=c;
        }

        //two
        temp[0]=r[2];temp[1]=r[1];temp[2]=r[5];temp[3]=r[0];temp[4]=r[4];temp[5]=r[3];temp[6]='\0';
        for(int i=0;i < 4;i++){
            if(strcmp(l,temp) == 0){
                printf("TRUE\n");
                goto l1;
            }
            char c=temp[1];
            temp[1]=temp[2];temp[2]=temp[4];temp[4]=temp[3];temp[3]=c;
        }
        temp[0]=r[3];temp[1]=r[1];temp[2]=r[0];temp[3]=r[5];temp[4]=r[4];temp[5]=r[2];temp[6]='\0';
        for(int i=0;i < 4;i++){
            if(strcmp(l,temp) == 0){
                printf("TRUE\n");
                goto l1;
            }
            char c=temp[1];
            temp[1]=temp[2];temp[2]=temp[4];temp[4]=temp[3];temp[3]=c;
        }
        printf("FALSE\n");
    }
    return 0;
}

抱歉!评论已关闭.