#C6395. Final Position of the Robot
Final Position of the Robot
Final Position of the Robot
You are given a string cmd
consisting of characters 'U'
, 'D'
, 'L'
, and 'R'
which represent movements of a robot: up, down, left, and right respectively. Your task is to compute the final position \( (x, y) \) of the robot after executing all the commands.
The moves are defined as follows:
- U: move up by 1 unit (i.e. \( y = y + 1 \))
- D: move down by 1 unit (i.e. \( y = y - 1 \))
- L: move left by 1 unit (i.e. \( x = x - 1 \))
- R: move right by 1 unit (i.e. \( x = x + 1 \))
For example:
Input: UDLR Output: 0 0
Write a program that reads a command string from stdin and prints the final coordinates to stdout separated by a space.
inputFormat
The input is a single line containing a string cmd
which represents the series of commands. It contains only the characters 'U', 'D', 'L', and 'R'.
outputFormat
Output two integers separated by a space, representing the final x and y coordinates of the robot after executing the commands.
## sampleUDLR
0 0