Pagini recente » Cod sursa (job #2797998) | Cod sursa (job #740793) | Cod sursa (job #1860492) | Cod sursa (job #625987) | Cod sursa (job #440947)
Cod sursa(job #440947)
#include <cstdio>
#include <vector>
#include <algorithm>
struct point {
long x,y;
};
struct slope {
long slope;
};
bool test(slope a, slope b) { return (a.slope<b.slope); }
int main() {
FILE *f,*g;
f = fopen("trapez.in","r");
g = fopen("trapez.out","w");
int n;
fscanf(f,"%d\n",&n);
point a [n+1];
for(int i=0; i<n; i++) {
fscanf(f,"%d %d\n",&a[i].x,&a[i].y);
}
std::vector<slope> b;
slope aux;
for(int i=0; i<n-1; i++) {
for(int j=i+1; j<n; j++) {
if (a[j].x-a[i].x==0) aux.slope = 32000;
else aux.slope = (a[j].y-a[i].y)/(a[j].x-a[i].x);
b.push_back(aux);
}
}
sort(b.begin(), b.end(), test);
int rez = 0;
for(int i=1; i!=(int)b.size();i++) {
if (b[i-1].slope==b[i].slope) {
rez++;
i = i+2;
}
}
fprintf(g,"%d",rez);
fclose(f);
fclose(g);
}