253-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 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 isB,R, OrG. The character
() From the left gives the color of faceI. For example, Figure 2 is a pictureRbgggrAnd 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 abve,FALSEOtherwise.
Sample Input
rbgggrrggbgrrrrbbbrrbbbrrbgrbgrrrrrg
Sample tput
TRUEFALSEFALSE
Thinking questions about the WordPress 253:
This problem is complicated at first ~~ There are many situations to list ~~~
In fact, it is quite clear to think about the ideas.
Finally, it is concluded that for a box with a fixed position at the beginning, there will be 24 transformations (including itself)
First, determine the upper and lower positions
Then, determine the order of the surrounding images.
There are three types of order around the top and bottom positions. There are four types of order.
For example, if 16 is the upper and lower ends, there will be 4 cases.
},
25 is the upper and lower bottom, and 4 is the case
},
43. There are four scenarios for bottom-up and bottom-up.
}};
Then 61 is in the opposite order of 16.
, Which is opposite to, respectively.
The result
Below is the code
# Include <stdio. h> # include <string. h> int a [15] [9] = }, }, }}; // determine 12 cases and draw the opposite conclusion: char ans [26] [8]; char sample [20]; char input [10], output [10], converse [10]; void inout () {int I, j; for (I = 0; I <6; I ++) {input [I] = sample [I];} input [I] = '\ 0'; for (j = 0; j <6; J ++, I ++) {output [j] = sample [I];} output [j] = '\ 0 '; // printf ("% s \ n", input, output);} void changeform () {int I, j, k; for (I = 1; I <= 12; I ++) {for (j = 0; j <6; j ++) ans [I] [j] = input [a [I] [j]-1]; ans [I] [j] = '\ 0 ';} // for (I = 1; I <= 12; I ++) // printf ("% s \ n", ans [I]);} void conver () {char temp2, temp4, temp3; temp2 = output [2]; temp4 = output [4]; temp3 = output [3]; output [4] = temp2; output [2] = temp3; output [3] = temp4; int I, j; fo R (I = 5, j = 0; j <6; j ++, I --) converse [j] = output [I]; converse [j] = '\ 0'; // printf ("% s \ n", converse);} int check () {int I, j, flag = 0; for (I = 1; I <= 12; I ++) {if (strcmp (ans [I], output) = 0) {flag = 1; break ;} if (strcmp (ans [I], converse) = 0) {flag = 1; break;} return flag;} int main () {while (scanf ("% s", sample )! = EOF) {inout (); // extract the color arrangement of two cubes from the input data changeform (); // enumerate all the 12 cases of conver (); // change the data format if (check () = 1) printf ("TRUE \ n "); // verify the data conclusion else printf ("FALSE \ n ");}}