#include #include #include #include #include #include #include using namespace std; int main() { ifstream ifs{"WAYPOINTS"}; vector> waypoints{}; transform(istream_iterator{ifs}, istream_iterator{}, inserter(waypoints, begin(waypoints)), [] (string const& line) { auto it{find(begin(line), end(line), '-')}; return make_pair(stoi(string{begin(line), it}), stoi(string{next(it), end(line)})); }); double d{inner_product(begin(waypoints), prev(end(waypoints)), next(begin(waypoints)), 0.0, plus<>(), [] (pair const& from, pair const& to) { int difference_x{abs(from.first - to.first)}; int difference_y{abs(from.second - to.second)}; cout << difference_x << " " << difference_y; double hypotenuse{sqrt(pow(difference_x, 2) + pow(difference_y, 2))}; cout << " " << hypotenuse << endl; return hypotenuse; })}; for( auto e : waypoints ) cout << e.first << " " << e.second << endl; cout << d << endl; }