#K41767. Plane Navigation System
Plane Navigation System
Plane Navigation System
You are given a simulation of a plane navigation system. The plane starts at the origin (0, 0) and receives a series of commands to update its position or measure distances.
The commands are:
- move x y: Moves the plane to the new position (x, y).
- distance x y: Calculates the Euclidean distance from the current plane's position to the point (x, y). The distance is computed using the formula: $$\sqrt{(x - x_0)^2 + (y - y_0)^2}$$ and rounded to six decimal places.
- origin: Resets the plane's position to the origin (0, 0).
Your task is to process the commands and output the results of every distance
command on a new line. If no distance
command is issued, output nothing.
inputFormat
The input is read from standard input and has the following format:
n command_1 command_2 ... command_n
Here, n
is a positive integer representing the total number of commands. Each of the following n
lines represents a command as described above.
outputFormat
For each distance
command, output the computed distance rounded to six decimal places on a new line. If no distance
commands are executed, do not print anything.
6
move 3 4
distance 0 0
move 1 1
distance 3 3
origin
distance 2 2
5.000000
2.828427
2.828427
</p>