#C8951. Drone Final Position
Drone Final Position
Drone Final Position
You are given a string representing a sequence of movement instructions for a drone on a 2D plane. The instructions are given as characters: U
(up), D
(down), L
(left), and R
(right). Starting from the origin (0, 0), compute the final coordinates of the drone after executing all movements.
For each instruction:
- U: Increase the y-coordinate by 1.
- D: Decrease the y-coordinate by 1.
- L: Decrease the x-coordinate by 1.
- R: Increase the x-coordinate by 1.
You can mathematically express the final coordinates as:
\[ x = \sum_{i=1}^{n} \delta_{i}(x), \quad y = \sum_{i=1}^{n} \delta_{i}(y) \]
where \(\delta_{i}(x)\) and \(\delta_{i}(y)\) represent the changes in the x and y coordinates caused by the i-th move, respectively.
Note that the input movements are passed as a single string via standard input (stdin), and the output must be printed to standard output (stdout) as two space-separated integers representing the final x and y coordinates.
inputFormat
The input consists of a single line containing a string of characters. Each character is one of U
, D
, L
, or R
representing a move.
Example: UUDDLRLR
outputFormat
Output two integers separated by a space representing the final x and y coordinates of the drone.
Example: 0 0
0 0