#P2007. Rubik's Cube Simulation
Rubik's Cube Simulation
Rubik's Cube Simulation
Rubik's Cube Simulation
In this problem, you are given the configuration of a standard 3×3×3 Rubik's Cube and a sequence of moves (or algorithms) that have been applied to it. The cube follows the conventional color scheme: Up (U) is white (W), Down (D) is yellow (Y), Front (F) is red (R), Back (B) is orange (O), Left (L) is green (G), and Right (R) is blue (B). Initially the cube is in a solved state, with each face a uniform color as described.
The moves are given in standard notation. For example, U denotes turning the Up face 90° clockwise, and U' denotes turning it 90° counterclockwise. The possible moves are U, D, F, B, L, and R (and their inverses with a trailing apostrophe). After executing the given moves in order, output the final configuration of the cube.
The cube is represented by its 6 faces in the order: U, D, F, B, L, R. Each face is described by a string of 9 characters (in row‐major order) representing the colors on that face. For example, the solved cube will be:
U: WWWWWWWWW D: YYYYYYYYY F: RRRRRRRRR B: OOOOOOOOO L: GGGGGGGGG R: BBBBBBBBB
Your task is to simulate the moves and output the final configuration in the same order (6 lines, one for each face).
inputFormat
Input Format
The input consists of several lines:
- The first 6 lines describe the cube's initial configuration. Each line is a string of 9 characters representing a face in the order U, D, F, B, L, R. (The solved cube is given as shown in the sample.)
- The next line contains an integer n (n ≥ 0), the number of moves.
- The following n lines each contain a move. A move is one of: U, U', D, D', F, F', B, B', L, L', R, or R'.
Note: It is guaranteed that n is at least 0. For some test cases no moves are performed.
outputFormat
Output Format
Print 6 lines (in order: U, D, F, B, L, R), each line is the final configuration (a string of 9 characters) of the corresponding face after all moves have been executed.
sample
WWWWWWWWW
YYYYYYYYY
RRRRRRRRR
OOOOOOOOO
GGGGGGGGG
BBBBBBBBB
0
WWWWWWWWW
YYYYYYYYY
RRRRRRRRR
OOOOOOOOO
GGGGGGGGG
BBBBBBBBB
</p>