Created
December 9, 2019 10:21
-
-
Save marty1885/eadc11b648fb2a8b4d9e8a0028c34e39 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <fstream> | |
#include <tuple> | |
#include <vector> | |
#include <iostream> | |
int main() | |
{ | |
using vec2d = std::tuple<float, float>; | |
std::ifstream in("input.txt"); | |
float x, y; | |
std::vector<vec2d> coords; | |
while(in >> x >> y) | |
coords.push_back(std::tuple(x, y)); | |
auto dist = [](const vec2d& a, const vec2d& b) -> float{ | |
float [x1, y1] = a; | |
float [x2, y2] = b; | |
return std::sqrt( | |
std::pow(x1-x2, 2) + | |
std::pow(y1-y2, 2));) | |
}; | |
std::ofstream out("DistMatrix.txt"); | |
for(const vec2d& p1 : coords) { | |
for(const vec2d& p2 : coords) { | |
// A hacky way to calculate if we are at the end of the vector | |
std::cout << dist(p1, p2) << (&p2 == &coords[coords.size()-1] ? "" : "\t"); | |
out << dist(p1, p2) << (&p2 == &coords[coords.size()-1] ? "" : "\t"); | |
} | |
cout << '\n'; | |
out << '\n'; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment