## Evan's Cube

View as PDF

Points: 12 (partial)
Time limit: 1.0s
Memory limit: 128M

Author:
Problem type
Allowed languages
Java

A Rubik's Cube is a 3-D combination puzzle. The cube consists of six faces, each of which is covered by nine stickers. The stickers are one of six solid colours: white, red, blue, orange, green, and yellow. Initially, the cube is "scrambled", meaning that each of the nine stickers on each face are a random colour. The goal of the Rubik's Cube is to "solve" it, making each face of the cube one specific colour, through a series of rotations.

There are exactly six faces to a Rubik's Cube. Each face can be "rotated" clockwise or counter-clockwise. We will denote each face a number between one and six, and C for a clockwise rotation and W for a counter-clockwise rotation. If we imagine a cube facing directly towards us, face 1 denotes the face facing towards us, face 2 the one facing to the left, face 3 the one facing away, face 4 the one facing to the right, face 5 the one facing down, and face 6 the one facing up. When we rotate a face clockwise, we are imagining as if we are looking directly at the face, and rotating the face to the right. The opposite is true for a counter-clockwise rotation.

You are given a scrambled Rubik's Cube and a series of rotations that were performed on it. Can you determine if the cube is "solved" after this series of rotations?

Online Rubik's Cube Simulator

#### Input Specification

The first lines will each contain characters. These will denote the colours of the nine stickers on face 1. The characters will be one of W,R,B,O,G,Y, denoting white, red, blue, orange, green, and yellow, respectively.

The next lines will follow a similar format as the first lines. These will denote face 2.
The next lines will denote the colours on face 3.
The next lines will denote the colours on face 4.
The next lines will denote the colours on face 5.
The next lines will denote the colours on face 6.

All faces are given as if you are facing it directly. For faces , they are given with face facing down and face facing up. For faces and , they are given with face facing up and face facing down.

It is guaranteed that there will be exactly nine of each of the six colours.

The next line will contain the integer , the number of rotations that were performed. There will be at most operations performed on the cube.

The next lines will each contain a string of the form FD. F is the face that is being rotated, and D is either C for a clockwise rotation or W for a counter-clockwise rotation.

Note that in this problem, the middle section cannot be rotated directly, only the faces.

#### Output Specification

Output Solved! if the Rubik's Cube is solved after the rotations, or Boo! if it is not solved.

#### Constraints

Note: you do NOT need to pass the sample test cases to pass some of the subtasks.

There will be no rotations.

There will be at most one rotation.

#### Sample Input 1

WWW
WWW
WWW
RRR
RRR
RRR
BBB
BBB
BBB
OOO
OOO
OOO
GGG
GGG
GGG
YYY
YYY
YYY
1
1C

#### Sample Output 1

Boo!

#### Explanation For Sample 1

The cube was initially solved, but the one clockwise rotation on face 1 unsolved it. Boo!

#### Sample Input 2

RRB
WWW
RRB
YYY
RRB
YYY
GOO
YYY
GOO
WWW
GOO
WWW
BBO
BBO
BBO
RGG
RGG
RGG
3
6C
5W
1W

#### Sample Output 2

Solved!