Welcome to ZOJ
Information
Select Problem
Runs
Ranklist
ZOJ Problem Set - 1208
Roll the Die!

Time Limit: 2 Seconds      Memory Limit: 65536 KB

A gambler's die (Figure 1) is a cube whose six faces are labeled with 1, 2, 3, 4, 5, and 6 dots, respectively.

Each of the faces 1, 2, and 3 is adjacent to the other two.

If the die is viewed so that faces 1, 2, and 3 are visible, face 1 is on top, and face 2 is in front, then face 3 will be seen on the right side of the die, as in the figure on the right.

Faces 4, 5, and 6 are opposite to faces 3, 2, and 1, respectively.

In the scenario of this problem, a die will be placed on top of a horizontal xy-plane (Figure 2).

One unit length in the xy-plane is equal to the side length of the die.

Initially, the center of the bottom face of the die will coincide with point (0, 0)of the xy-plane.

The xy-plane is situated so that the positive y-axis points to the north, and the positive x-axis points to the east.

The die will always be observed from the south (looking north), so that the front side of the die is the one facing south.

The action which will be performed on the die will be referred to as "rolling the die". This action, however, will be very different from the conventional meaning of rolling a die.

The die will always be rolled in one of the four directions north, south, east, and west.

Rolling the die to the north, for example, will mean that the die is rotated through an angle of 90 degrees about its north bottom edge.

Starting with position and configuration shown in Figure 2, let us roll the die to the north.

The position of the die will now change from (0, 0) to (0, 1).

The face 2 will now be on top and the face 6 will be in front.

The resulting position and configuration are shown in Figure 3.

A further roll to the east will change the position to (1, 1) and bring face 4 to the top, as shown in Figure 4.

Here is an example of the input to your program:

1 2 W W W N
1 2 N W W W
1 6 S S S W W W W W
3 3 N N S
4 6 E W W S S S S E S S S S S S S E E S S S S S S E

Each line of the input consists of:

Two integers in the range 1..6, separated by one blank space.

These integers specify the initial orientation of the die. (As stated above, the initial position of the die is always (0, 0), so it does not need to be specified.)

The first of the two integers specifies the top face of the die, the second one specifies its front face.

One or more (but not more than 35) upper case letters, each of which is 'N', 'S', 'E', or 'W'.

Each letter is preceded by one blank space.

These letters specify a sequence of rolls of the die. Each roll will occur to the north, south, east, or west, as indicated by the corresponding upper case letter.

Given the above input, your program will write the following output:

Problem 2 by team x

Initial orientation:             top = 1  front = 2
Moves: W W W N
Final orientation and position:  top = 2  front = 3  x =  -3  y =   1

Initial orientation:             top = 1  front = 2
Moves: N W W W
Final orientation and position:  top = 4  front = 6  x =  -3  y =   1

Invalid initial orientation:     top = 1  front = 6

Invalid initial orientation:     top = 3  front = 3

Initial orientation:             top = 4  front = 6
Moves: E W W S S S S E S S S S S S S E E S S S S S S E
Final orientation and position:  top = 2  front = 4  x =   3  y = -17
End of problem 2 by team x

For each line of input that contains a valid initial orientation (such as lines 1, 2, and 4 in the above example), there will be exactly four lines of output:

A blank line.

A line specifying the initial orientation, read from the input.

A line specifying the sequence of moves, read from the input.

A line specifying the final orientation and position of the die. You may assume that the values of x and y will be in the range -99..99.

For each line of input that contains an invalid initial orientation (the two given faces of the die are not adjacent, or the same face is given for the top and the front), there will be exactly two lines of output:

A blank line.

A line stating that the initial orientation is invalid and specifies the values of top and front, read from the input.

Observe every detail of the output, such as the exact wording and punctuation of statements, upper/lower case variations, blank lines and blank spaces. Note in particular, that the values of top and front are printed in fields of width 2, whereas the values of x and y are printed in fields of width 4 (including the blank space which follows the equal sign).

A few lines of the above output will be reproduced here with formatting templates:

         1         2         3         4         5         6         7
1234567890123456789012345678901234567890123456789012345678901234567890
Invalid initial orientation:     top = 1  front = 6

Initial orientation:             top = 4  front = 6
Moves: E W W S S S S E S S S S S S S E E S S S S S S E
         1         2         3         4         5         6         7
1234567890123456789012345678901234567890123456789012345678901234567890
Final orientation and position:  top = 2  front = 4  x =   3  y = -17
End of problem 2 by team x


Source: Rocky Mountain 1999
Submit    Status