#K54352. Robot Move
Robot Move
Robot Move
In this problem, you are given a string of commands that direct a robot to move on a 2D plane. The commands consist solely of the characters 'U', 'D', 'L', and 'R', which represent moves Up, Down, Left, and Right respectively. The robot starts at the origin (0, 0) and processes the commands sequentially.
Your task is to compute the final position of the robot after executing all the commands. The final position should be printed as two space-separated integers representing the x and y coordinates respectively.
The updating rules for the moves are given by the formulas below:
- For 'U': \( y = y + 1 \)
- For 'D': \( y = y - 1 \)
- For 'L': \( x = x - 1 \)
- For 'R': \( x = x + 1 \)
For example, if the command string is UUDDRL
, the final position of the robot will be 0 0
.
inputFormat
The input consists of a single line containing a string of commands. The string may be empty.
Note: Read from standard input (stdin).
outputFormat
Output a single line containing two integers separated by a space that represent the final x and y coordinates of the robot after executing the commands. Write the output to standard output (stdout).
## sampleUUDDRL
0 0