Cube painting

Uva 253 – Cube painting

Cube painting

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) from the left gives the color of facei. For example, Figure 2 is a picture ofrbgggrand Figure 3 corresponds torggbgr. 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 containsTRUEif the second half can be obtained from the first half by rotation as describes above,FALSEotherwise.

Sample Input

rbgggrrggbgrrrrbbbrrbbbrrbgrbgrrrrrg

Sample Output

TRUEFALSEFALSE

#include<stdio.h>#include<string.h>int operation(char* base, char* temp){int i, j, cnt;char sutemp[8];static int subtimes[][4] = {{2,3,4,5},{4,2,5,3},{3,5,2,4},{5,4,3,2}};sutemp[0] = temp[0];sutemp[5] = temp[5];sutemp[;for(i=0; i<4; ++i){for(j=0,cnt=1; j<4; ++j, ++cnt)sutemp[cnt] = temp[subtimes[i][j]-1];if(strcmp(base, sutemp) == 0) return 1;}return 0;}int main(){char input[18], cub1[10], cub2[10], temp[10];int i, flag, j, cnt;int times[][6] = {{1,2,3,4,5,6},{2,1,4,3,6,5},{3,2,6,1,5,4},{4,2,1,6,5,3},{5,1,3,4,6,2},{6,2,4,3,5,1}};, input) != EOF){flag = 0;cub1[;memcpy(cub1, input, sizeof(char)*6);memcpy(cub2, input+6, sizeof(char)*6);if(strcmp(cub1, cub2) == 0) flag = 1;else{for(i=0; i<6; ++i){for(j=cnt=0; j<6; ++j, ++cnt)temp[cnt] = cub2[times[i][j]-1];temp[cnt] = ;flag = operation(cub1, temp);if(flag) break;}}););}return 0;}

解题思路:

这题对于我来说,没有所谓的技巧,纯粹的遍历,虚拟主机,看到题目的人都会有的想法只是被我实现了,理所当然的,不缺乏普遍的缺陷,香港虚拟主机,麻烦冗长,无技巧,香港服务器租用,但最后我还是有所WA

遍历24种情况,花不了多少的时间,所以这样做还是能够接受的。

posted on

世上最累人的事,莫过於虚伪的过日子

Cube painting

相关文章:

你感兴趣的文章:

标签云: