Cod sursa(job #1844291)

Utilizator Razvanel6991Razvan Lazar Razvanel6991 Data 9 ianuarie 2017 21:18:25
Problema Trapez Scor 30
Compilator c Status done
Runda Arhiva de probleme Marime 1.09 kb
#include <stdio.h>
#include <stdlib.h>

typedef struct point{
	int x, y;
}Point;

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;
}

void sortArray(double *v, int k){
	double temp;
	for(int i = 0; i < k - 1; i++){
		for(int j = i + 1; j < k; j++){
			if(v[i] > v[j]){
				temp = v[i];
				v[i] = v[j];
				v[j] = temp;
			}
		} 
	}
}

int getResult(double *v, int k){
	double val = v[0] - 1;
	int total = 0;
	for(int i = 0; i < k; i++){
		if(v[i] == val){
			total++;
		}
		else{
			val = v[i];
		}
	}
	return total; 
}
int main(){
	FILE *in, *out;
	int N, k = 0;
	Point array[1000];
	double slopes[100000];
	in = fopen("trapez.in", "r");
	out = fopen("trapez.out", "w");
	fscanf(in, "%d", &N);
	for( int i = 0; i < N; i++){
		fscanf(in, "%d", &array[i].x);
		fscanf(in, "%d", &array[i].y);
	}

	for(int i = 0; i < N - 1; i++){
		for(int j = i + 1; j < N; j++){
			slopes[k++] = getSlope(array[i].x, array[j].x, array[i].y, array[j].y);
		}
	}

	sortArray(slopes, k);
	fprintf(out, "%d\n", getResult(slopes, k));
	return 0;
}