#C7005. Robot Final Position
Robot Final Position
Robot Final Position
You are given a series of commands that control the movement of a robot on a 2D plane. The commands consist of the characters U
, D
, L
, and R
representing up, down, left, and right moves respectively. The robot starts at the origin (0, 0). For each command, update the robot's position accordingly:
- U: Increase the y-coordinate by 1.
- D: Decrease the y-coordinate by 1.
- L: Decrease the x-coordinate by 1.
- R: Increase the x-coordinate by 1.
You are required to process multiple test cases. For each test case, output the final coordinate of the robot in the format x y
on a separate line.
The movement can be described by the following formulas in LaTeX format:
$$ x = \sum_{i=1}^{n} \delta_{x}(command_i), \quad y = \sum_{i=1}^{n} \delta_{y}(command_i) $$
where \( \delta_{x}(\cdot) \) and \( \delta_{y}(\cdot) \) represent the change in the x and y coordinates respectively for each command.
inputFormat
The first line of input contains an integer T
representing the number of test cases.
Each of the next T
lines contains a single string composed of the characters U
, D
, L
, and R
. This string represents the sequence of commands for that test case. Note that the string may be empty, which means no movement.
outputFormat
For each test case, output a single line with two integers: the final x and y coordinates of the robot after executing all commands.
The coordinates should be separated by a space.
## sample3
UUUDD
LLRR
UDLR
0 1
0 0
0 0
</p>