#C4844. Robot Final Position
Robot Final Position
Robot Final Position
You are given a robot initially located at the origin \((0,0)\). The robot receives a sequence of commands which moves it one unit in the specified direction with each command. The commands are given in a string consisting of the characters 'U', 'D', 'L', and 'R' which correspond to up, down, left, and right respectively.
The first input is an integer \(n\) which represents the number of commands, followed by a string of commands of length \(n\). Your task is to compute the final coordinates of the robot after executing all the commands.
Note: Although the integer \(n\) is provided, you can also derive the number of commands from the length of the string.
Example:
Input: 5 UUDLR</p>Output: 0 1
In the example above, the robot moves up twice, down once, left once, and right once, resulting in a final position of \((0,1)\).
inputFormat
The input is provided via standard input (stdin) and consists of two lines:
- An integer \(n\) representing the number of commands.
- A string of \(n\) characters where each character is one of: 'U', 'D', 'L', or 'R'.
outputFormat
The output should be printed to standard output (stdout) as two integers separated by a space representing the final \(x\) and \(y\) coordinates of the robot.
For the input example given above, the output is:
0 1## sample
5
UUDLR
0 1
</p>