#include #include /** * Computes the Euclidean distance between two points (x1, y1) and (x2, y2). * * @param x1 a double * @param y1 a double * @param x2 a double * @param y2 a double * @return the Euclidean distance between (x1, y1) and (x2, y2) */ double euclidean_distance(double, double, double, double); /** * Reads points in plane from standard input in form * * 0 0 * 1 1 * 3 1 * 4 0 * * and outputs the total length of the segments that * connect them. * * Compile with * * g++ -Wall -pedantic -std=c++17 -o Distance distance.cpp * * and then run with * * ./Distance */ int main(int argc, char **argv) { double last_x, last_y; double x, y; double total_distance = 0.0; std::cin >> last_x >> last_y; // extract from stream cin (standard input) while (std::cin >> x >> y) { total_distance += euclidean_distance(last_x, last_y, x, y); last_x = x; last_y = y; } std::cout << total_distance << std::endl; } double euclidean_distance(double x1, double y1, double x2, double y2) { double d = std::sqrt(std::pow(x1 - x2, 2) + std::pow(y1 - y2, 2)); return d; }