P0002. Business representative

A business representative does a series of routes in the city. Each
route starts in a point, he goes to some shops and comes back to the
origin.

Your task is to write a program that reads several routes and, for each
one, prints the total done distance supposing that the movements among
shops are done in straight line.

Your program must include the function

        double distance(double x1, double y1, double x2, double y2);

that returns the Euclidean distance between the points (|x1|, |y1|) and
(|x2|, |y2|).

Input

The input is a sequence of routes. Every route starts with a word that
identifies it, and then, there is a sequence of two or more pairs of
doubles that represent the coordinates of the visited places. The final
point always coincides with the starting point, and it appears only at
the beginning and in the end of each sequence of coordinates.

Output

Your program must print the total Euclidean distance of each route
given, following the format of the instance. The distances must be
written with 4 digits behind the dot.

Observation

Remember that the Euclidean distance between two points (x₁, y₁) and
(x₂, y₂) is

$$\sqrt{(x_1-x_2)^2 + (y_1-y_2)^2} \enspace .$$

Problem information

Author: Unknown
Translator: Carlos Molina

Generation: 2026-01-25T10:34:35.595Z

© Jutge.org, 2006–2026.
https://jutge.org
