Pagini recente » Cod sursa (job #2190882) | Cod sursa (job #2818366) | Cod sursa (job #1000547) | Cod sursa (job #2142485) | Cod sursa (job #2619148)
#include <fstream>
#include <limits>
#include <map>
#define N 1000
std:: ifstream f;
std::ofstream g;
struct coord{
float x, y;
};
int main()
{
int n;
coord vect[N];
std::map<float, int> xd;
long trapeze = 0;
f.open("trapez.in");
f >> n;
for (int i = 0; i < n; i++) {
f >> vect[i].x;
f >> vect[i].y;
}
f.close();
for (int i = 0; i < n - 1; i++) {
for (int j = i + 1; j < n; j++) {
try {
xd[(vect[j].y - vect[i].y) / (vect[j].x - vect[i].x)]++;
}
catch(...) {
xd[std::numeric_limits<float>::infinity()]++;
}
}
}
for (std::pair<float, int> entry : xd) {
trapeze += (entry.second * (entry.second - 1)) / 2;
}
g.open("trapez.out");
g << trapeze;
}