#K78127. Robot Movements on a Grid

    ID: 35018 Type: Default 1000ms 256MiB

Robot Movements on a Grid

Robot Movements on a Grid

A robot is placed on a 2D grid at a given initial coordinate. It then executes a sequence of movement commands. The commands are given as single characters: U (up), D (down), L (left), and R (right). For each dataset, the robot starts at the specified initial coordinate and processes a series of commands to update its position. The input terminates with a line that contains exactly 0 0 (without extra characters), which signals that there are no more datasets to process.

Details:

  • The first line of each dataset contains two integers representing the starting x and y coordinates.
  • The second line contains an integer n, the number of movement commands that follow.
  • The subsequent n lines each contain one command character (one of U, D, L, or R).
  • A dataset that is exactly 0 0 (with no extra commands) should not be processed and indicates the end of input.

The final output for each dataset is the resulting coordinate after executing all the commands, printed as two integers separated by a space. Each result should be printed on its own line.

inputFormat

The input consists of several datasets. Each dataset is formatted as follows:

  1. A line with two integers, x and y, representing the starting coordinates.
  2. A line with an integer n, the number of commands.
  3. n lines, each containing a single character (U, D, L, or R) representing a movement command.

The input ends with a line that contains exactly 0 0, which should not be processed.

outputFormat

For each dataset (except the terminating one), output a single line with two integers separated by a space. These integers represent the final x and y coordinates of the robot after executing all the commands.

## sample
3 4
5
U
R
D
L
U
1 1
4
R
R
U
L
0 0
3 5

2 2

</p>