253 - Cube painting UVA
来源:互联网 发布:化妆品真伪查询软件 编辑:程序博客网 时间:2024/05/08 19:51
We have a machine for painting cubes. It is supplied with three different colors: blue, red and green. Each face of the cube gets one of these colors. The cube's faces are numbered as in Figure 1.
Figure 1.
Since a cube has 6 faces, our machine can paint a face-numbered cube in different ways. When ignoring the face-numbers, the number of different paintings is much less, because a cube can be rotated. See example below. We denote a painted cube by a string of 6 characters, where each character is a b, r, org. The character ( ) from the left gives the color of face i. For example, Figure 2 is a picture of rbgggr and Figure 3 corresponds to rggbgr. Notice that both cubes are painted in the same way: by rotating it around the vertical axis by 90 , the one changes into the other.
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
rbgggrrggbgrrrrbbbrrbbbrrbgrbgrrrrrg
Sample Output
TRUEFALSEFALSE
字符串写的……字符串...#include<stdio.h>#include<string.h>int judge(char str1[7],char str2[7],int u){ int i,j,k,t; char s[5],s1[5]; if(str1[0]!=str2[0]||str1[5]!=str2[5]) return 2; else { t=0; for(i=1;i<=4;i++) { if(i==1) s1[0]=str1[1]; if(i==3) s1[1]=str1[i]; if(i==4) s1[2]=str1[i]; if(i==2) s1[3]=str1[i]; } s1[4]=0; for(i=1;i<=4;i++) { t=0; for(j=i,k=1;k<=4;j++,k++) { if(j>4) j=j-4; s[t++]=str2[j]; } s[t]=0; if(strcmp(s,s1)==0) { return 1; } } return 2; }}int main(){ char str[14],str1[7],str2[7],s2[7]; int i,j,k,t; int flag; while(scanf("%s",str)!=EOF) { t=0; for(i=0;i<=5;i++) { str1[t++]=str[i]; } str1[t]=0; t=0; for(i=6;i<=11;i++) { str2[t++]=str[i]; } str2[t]=0; for(i=1;i<=6;i++) { if(i==1) { s2[0]=str2[0]; s2[5]=str2[5]; s2[1]=str2[1]; s2[2]=str2[3]; s2[3]=str2[4]; s2[4]=str2[2]; } if(i==2) { s2[0]=str2[1]; s2[5]=str2[4]; s2[1]=str2[5]; s2[2]=str2[3]; s2[3]=str2[0]; s2[4]=str2[2]; } if(i==3) { s2[0]=str2[2]; s2[5]=str2[3]; s2[1]=str2[5]; s2[2]=str2[1]; s2[3]=str2[0]; s2[4]=str2[4]; } if(i==4) { s2[0]=str2[3]; s2[5]=str2[2]; s2[1]=str2[1]; s2[2]=str2[5]; s2[3]=str2[4]; s2[4]=str2[0]; } if(i==5) { s2[0]=str2[4]; s2[5]=str2[1]; s2[1]=str2[5]; s2[2]=str2[2]; s2[3]=str2[0]; s2[4]=str2[3]; } if(i==6) { s2[0]=str2[5]; s2[5]=str2[0]; s2[1]=str2[4]; s2[2]=str2[3]; s2[3]=str2[1]; s2[4]=str2[2]; } s2[6]=0; flag=judge(str1,s2,i); if(flag==1) { printf("TRUE\n"); break; } } if(flag!=1) { printf("FALSE\n"); } } return 0;}
刚开始想错了,错了三次怎么都改不好。。后来理了一下思路敲出来了AC。。
勿喷~
- UVa 253 - Cube painting
- Uva 253 - Cube painting
- Uva 253 Cube Painting
- uva 253 Cube painting
- uva 253 - Cube painting
- UVa 253 - Cube painting
- UVA 253 - Cube painting
- UVA 253 - Cube painting
- UVA 253 Cube painting
- UVa 253: Cube painting
- uva 253 - Cube painting
- uva 253 Cube painting
- UVA 253 Cube painting
- 253 - Cube painting UVA
- UVa 253 Cube painting
- UVA-253-Cube painting
- UVa 253 - Cube painting
- UVA 253 Cube painting
- 9.HTML5 JavaScript DHTML
- 【ios 汇总 常见错误 crash】 分析
- ural - 1470 - UFOs(树状数组)
- ucos创建任务
- windows核心编程笔记(一)
- 253 - Cube painting UVA
- MySql 查询一周内最近7天记录
- POJ 1330 Nearest Common Ancestors LCA
- Python日志输出——logging模块
- mysql获取按日期排序获取最新的记录
- hdu 3336 Count the string(KMP)
- Learn Python The Hard Way-Ecercise26~30
- 没有RunInstallerAttribute.Yes的公共安装程序
- ubuntu(linux)系统根目录文件分类代表的含义