#C8531. Robot Movement Simulation
Robot Movement Simulation
Robot Movement Simulation
You are given a robot starting at an initial position \( (x, y) \) on the Cartesian plane. The robot receives a series of movement commands represented as a string consisting of the characters U
(up), D
(down), L
(left) and R
(right). For each command, the robot moves one unit in the corresponding direction.
Your task is to compute the final position of the robot after executing all given commands.
Movement rules:
U
: Increase \( y \) by 1D
: Decrease \( y \) by 1L
: Decrease \( x \) by 1R
: Increase \( x \) by 1
For example, starting at \( (0,0) \) and following the commands "UUDDLR" would result in the final position \( (0,0) \).
inputFormat
The first line of the input contains an integer \( T \) representing the number of test cases. Each of the following \( T \) lines contains a test case with the following format:
x y movements
Here, x
and y
are the initial coordinates of the robot, and movements
is a string composed of the characters U, D, L, and R.
outputFormat
For each test case, output the final position of the robot as two integers separated by a space on a new line.
## sample3
0 0 UUDDLR
2 3 LLRRDD
-1 -1 URDL
0 0
2 1
-1 -1
</p>