#C12174. Simulate Object Movement
Simulate Object Movement
Simulate Object Movement
You are given a sequence of movements for an object starting at the origin \((0, 0)\). Each movement is represented by a direction and a distance. The directions can be UP
, DOWN
, LEFT
, or RIGHT
. Your task is to compute the final coordinates of the object after performing all the movements.
The object initially starts at \((0, 0)\). For each movement:
- If the direction is
UP
, increase the y-coordinate by the given distance. - If the direction is
DOWN
, decrease the y-coordinate by the given distance. - If the direction is
LEFT
, decrease the x-coordinate by the given distance. - If the direction is
RIGHT
, increase the x-coordinate by the given distance.
Finally, output the final x and y coordinates separated by a space.
inputFormat
The input is read from stdin and has the following format:
- An integer \(n\) representing the number of movements.
- \(n\) lines follow, each line contains a string and an integer separated by space. The string represents the direction (
UP
,DOWN
,LEFT
, orRIGHT
) and the integer represents the distance.
outputFormat
Print the final x and y coordinates separated by a space. The output is written to stdout.
## sample0
0 0
</p>