#K70377. Final Robot Position
Final Robot Position
Final Robot Position
Sara is participating in a challenging robot programming competition. In this problem, you are required to simulate the movement of a robot on a 2D grid based on a sequence of commands. The robot starts at the origin \((0, 0)\) and moves according to the commands provided.
The available commands are:
- U — move up (i.e. increase \(y\) coordinate by 1)
- D — move down (i.e. decrease \(y\) coordinate by 1)
- L — move left (i.e. decrease \(x\) coordinate by 1)
- R — move right (i.e. increase \(x\) coordinate by 1)
Your task is to compute the final position \((x, y)\) of the robot for each test case after processing all commands.
Note: The answer for each test case should be printed on a new line in the format "x y".
inputFormat
The input is given from stdin
with the following format:
T commands_1 commands_2 ... commands_T
Where:
T
is an integer representing the number of test cases.- Each
commands_i
is a string consisting of characters 'U', 'D', 'L', 'R' representing the commands executed by the robot.
outputFormat
For each test case, output the final position of the robot as two space-separated integers x
and y
on a separate line. The output should be given to stdout
.
For example, if the final position is \((0, 0)\), the output should be:
0 0## sample
1
UUDDLRLR
0 0
</p>