#C3183. Final Robot Position
Final Robot Position
Final Robot Position
Given a string of commands, determine the final position of a robot on a 2D grid. The robot starts at the origin \((0,0)\) and processes each command sequentially. Each command is represented by a character and moves the robot one unit in the corresponding direction:
- U: Moves the robot up by increasing the y-coordinate by 1, i.e., \(y = y + 1\).
- D: Moves the robot down by decreasing the y-coordinate by 1, i.e., \(y = y - 1\).
- L: Moves the robot left by decreasing the x-coordinate by 1, i.e., \(x = x - 1\).
- R: Moves the robot right by increasing the x-coordinate by 1, i.e., \(x = x + 1\).
The final output should be the coordinates \(x\) and \(y\) after processing all commands.
inputFormat
A single line of input containing a string of characters. Each character is one of 'U', 'D', 'L', or 'R' representing a movement command. There are no spaces between the characters.
outputFormat
Print the final coordinates of the robot as two space-separated integers (x and y).## sample
UUUU
0 4
</p>