uva 253 Cube painting

来源:互联网 发布:cs拍照软件下载 编辑:程序博客网 时间:2024/04/19 21:10

一道简单题,把所有情况列举出来进行对比就行了,原来的顶面可能在旋转后出现在六个面任意一个,当顶面固定的时候,以顶面和底面的连线为轴旋转,会出现4中组合,把所有情况都考虑到就行了,我用的是暴力解法。

#include <stdio.h>#include <string.h>char color1[8];char color2[8];void func(){char temp[8];int i;bool f;char t;//分别对比6种情况f = false;temp[7] = '\0';//不旋转strcpy(temp+1, color1+1);if(temp[1]==color2[1] && temp[6]==color2[6]){if(!strcmp(temp+1,color2+1)){f = true; goto end;}for(i=1; i<=3; i++){t=temp[3]; temp[3]=temp[2]; temp[2]=temp[4]; temp[4]=temp[5]; temp[5]=t;if(!strcmp(temp+1,color2+1)){f = true; goto end;}}}//向左旋转一次temp[1] = color1[4];temp[2] = color1[2];temp[3] = color1[1];temp[4] = color1[6];temp[5] = color1[5];temp[6] = color1[3];if(temp[1]==color2[1] && temp[6]==color2[6]){if(!strcmp(temp+1,color2+1)){f = true; goto end;}for(i=1; i<=3; i++){t=temp[3]; temp[3]=temp[2]; temp[2]=temp[4]; temp[4]=temp[5]; temp[5]=t;if(!strcmp(temp+1,color2+1)){f = true; goto end;}}}//向左旋转两次temp[1] = color1[6];temp[2] = color1[2];temp[3] = color1[4];temp[4] = color1[3];temp[5] = color1[5];temp[6] = color1[1];if(temp[1]==color2[1] && temp[6]==color2[6]){if(!strcmp(temp+1,color2+1)){f = true; goto end;}for(i=1; i<=3; i++){t=temp[3]; temp[3]=temp[2]; temp[2]=temp[4]; temp[4]=temp[5]; temp[5]=t;if(!strcmp(temp+1,color2+1)){f = true; goto end;}}}//向右旋转一次temp[1] = color1[3];temp[2] = color1[2];temp[3] = color1[6];temp[4] = color1[1];temp[5] = color1[5];temp[6] = color1[4];if(temp[1]==color2[1] && temp[6]==color2[6]){if(!strcmp(temp+1,color2+1)){f = true; goto end;}for(i=1; i<=3; i++){t=temp[3]; temp[3]=temp[2]; temp[2]=temp[4]; temp[4]=temp[5]; temp[5]=t;if(!strcmp(temp+1,color2+1)){f = true; goto end;}}}//向前旋转一次temp[1] = color1[5];temp[2] = color1[1];temp[3] = color1[3];temp[4] = color1[4];temp[5] = color1[6];temp[6] = color1[2];if(temp[1]==color2[1] && temp[6]==color2[6]){if(!strcmp(temp+1,color2+1)){f = true; goto end;}for(i=1; i<=3; i++){t=temp[3]; temp[3]=temp[2]; temp[2]=temp[4]; temp[4]=temp[5]; temp[5]=t;if(!strcmp(temp+1,color2+1)){f = true; goto end;}}}//向后旋转一次temp[1] = color1[2];temp[2] = color1[6];temp[3] = color1[3];temp[4] = color1[4];temp[5] = color1[1];temp[6] = color1[5];if(temp[1]==color2[1] && temp[6]==color2[6]){if(!strcmp(temp+1,color2+1)){f = true; goto end;}for(i=1; i<=3; i++){t=temp[3]; temp[3]=temp[2]; temp[2]=temp[4]; temp[4]=temp[5]; temp[5]=t;if(!strcmp(temp+1,color2+1)){f = true; goto end;}}}end: if(f)printf("TRUE\n");elseprintf("FALSE\n");}int main(void){char buffer[20];while(gets(buffer)){memcpy(color1+1, buffer, 6);color1[7] = '\0';memcpy(color2+1, buffer+6, 6);color2[7] = '\0';func();}}


 

原创粉丝点击