Pagini recente » Cod sursa (job #2173246) | Cod sursa (job #3202130) | Cod sursa (job #2033893) | Cod sursa (job #368403) | Cod sursa (job #440945)
Cod sursa(job #440945)
#include <cstdio>
#include <vector>
#include <algorithm>
struct point {
long x,y;
};
struct slope {
int id1,id2;
float 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++) {
aux.id1 = i;
aux.id2 = j;
if (a[j].x-a[i].x==0) aux.slope = 32000;
else aux.slope = (float)(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);
}