Hide

Problem B
Boxed Turtle

Myrtle, the computerized box turtle, has had a cardboard box placed upside down over her. She is given a sequence of instructions for moving. If she has reached the side of the box, she pushes the box along with her. All moves of Myrtle and the box are rectilinear. Your task is to report the positions of Myrtle and the box after the moves are completed.

The box is 5 x 5 units square while Myrtle is just 1 x 1 unit square, each unit being 1 decimeter. Myrtle will begin and end each move inside one of the 25 unit squares of the box. The southwest corner of the box is initially placed at coordinate (0,0). You will be given the coordinates where Myrtle begins and what direction she is facing (always rectilinear). The initial direction is indicated by a compass letter $N$, $S$, $E$, or $W$. She makes moves of 1 unit each. A string of characters will indicate how Myrtle should move. Options are $F$ for forward, $L$ for turning 90 degrees left and then moving ahead one unit, $R$ for turning 90 degrees right and then moving ahead one unit, and $B$ for turning 180 degrees and then moving ahead one unit.

Input

Input is given on four lines. The first line contains two integer coordinates (ranging from 0 to 4) indicating the initial unit square of the box where Myrtle is placed. The next line contains Myrtle’s initial direction $N$, $S$, $E$, or $W$. The third line has a single integer that represents how many moves (at most 100) are provided on the fourth line. The fourth line has the string of moves.

Output

Output consists of three lines, formatted as in the sample. The first two lines have coordinate pairs and the third has a letter: 1) the final position of the box’s southwest corner, 2) the relative position of Myrtle in the box, and 3) the final direction Myrtle is facing, as compass point $N$, $S$, $E$, $W$. See the illustration of Sample 1 on the next page.


/problems/boxedturtles/file/statement/en/img-0001.jpg
Sample Input 1 Sample Output 1
3 2
N
6
FRFLFL
(1, 1) 
(3, 4)
W
Sample Input 2 Sample Output 2
0 0
S
2
FB
(0, -1) 
(0, 1)
N

Please log in to submit a solution to this problem

Log in