#C5869. Robot Final Position
Robot Final Position
Robot Final Position
A robot is placed at the origin (0, 0) on a two-dimensional plane. It receives a series of commands that instruct it to move in one of four directions: up (U), down (D), left (L), or right (R). Each command is accompanied by an integer representing the number of steps to move in that direction.
The final position can be computed using the formulas:
\( x_{final} = \text{(total steps to the right)} - \text{(total steps to the left)} \)
\( y_{final} = \text{(total steps up)} - \text{(total steps down)} \)
Your task is to determine the final coordinates of the robot after executing all the provided commands.
inputFormat
The input is given from standard input with the following format:
- The first line contains a single integer \(n\) indicating the number of commands.
- The following \(n\) lines each contain a command. Each command consists of a character (one of 'U', 'D', 'L', 'R') and an integer separated by a space, representing the direction and the number of steps.
outputFormat
Output the final position of the robot as two space-separated integers in a single line, representing \(x\) and \(y\) coordinates respectively.
## sample5
U 3
D 2
L 1
R 4
D 3
3 -2