Pagini recente » Cod sursa (job #1997567) | Istoria paginii runda/nimic_suspect2/clasament | Cod sursa (job #759745) | Istoria paginii runda/testqwerty/clasament | Cod sursa (job #1802843)
#include <fstream>
#include <vector>
#include <algorithm>
using namespace std;
struct punct
{
int x, y;
};
int main()
{
punct p[1001];
ifstream fin("trapez.in");
int i, j, n, x, y, numarator, numitor, nrtrapeze;
nrtrapeze = 0;
double jeg;
vector <double> pante;
fin >> n;
for(i = 0; i < n; i++)
{
fin >> p[i].x;
fin >> p[i].y;
}
fin.close();
for(i = 0; i < n; i ++)
for(j = i + 1; j < n; j ++)
{
numarator = p[j].y - p[i].y;
numitor = p[j].x - p[i].x;
if(numitor == 0)
pante.push_back(1000000);
else
{
jeg = (double)numarator / (double)numitor;
pante.push_back(jeg);
}
}
sort(pante.begin(), pante.end());
i = 0;
while (i < pante.size())
{
j = i + 1;
while(pante[j] == pante[j - 1] && j < pante.size())
j++;
nrtrapeze += (j - i) * (j - i - 1) / 2;
i = j;
}
ofstream fout("trapez.out");
fout << nrtrapeze;
fout.close();
return 0;
}