Pagini recente » Cod sursa (job #315957) | Cod sursa (job #1016302) | Cod sursa (job #304360) | Cod sursa (job #1737766) | Cod sursa (job #1844317)
#include <stdio.h>
#include <stdlib.h>
double getSlope(int x1, int x2, int y1, int y2){
if(x2 == x1){
return 1.005;
}
double slope = (double)(y2 - y1)/(x2 - x1);
return slope;
}
int getResult(double *v, int k){
int total = 0;
for(int i = 0; i < k -1; i++){
for(int j = i + 1; j < k; j++){
if(v[i] == v[j]){
total++;
}
}
}
return total;
}
int main(){
FILE *in, *out;
int N, k = 0;
int arr_x[1000], arr_y[1000];
double slopes[500500];
in = fopen("trapez.in", "r");
out = fopen("trapez.out", "w");
fscanf(in, "%d", &N);
if(N < 4){
fprintf(out, "%d\n", 0);
return 0;
}
for( int i = 0; i < N; i++){
fscanf(in, "%d", &arr_x[i]);
fscanf(in, "%d", &arr_y[i]);
}
for(int i = 0; i < N - 1; i++){
for(int j = i + 1; j < N; j++){
slopes[k++] = getSlope(arr_x[i], arr_x[j], arr_y[i], arr_y[j]);
}
}
fprintf(out, "%d\n", getResult(slopes, k));
return 0;
}