Cod sursa(job #1344957)

Utilizator MihailPJack ONeill MihailP Data 17 februarie 2015 09:38:38
Problema Orase Scor 10
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.82 kb
#include <stdio.h>
#include <stdlib.h>
struct city
{
	int L, D;

};
int DISTANCE(struct city C1, struct city C2)
{
	int D;
	D = C1.L + C2.L + abs(C1.D - C2.D);
	return D;
}
int MAX_CITY(struct city C1, struct city C2, struct city Ci)
{
	int D1, D2, max;
	D1 = DISTANCE(C1, Ci);
	D2 = DISTANCE(C2, Ci);
	if (D1 <= D2)
		max = D2;
	else
		max = D1;
	return max;
}
int main()
{
	FILE *f, *g;
	f = fopen("orase.in", "r");
	g = fopen("orase.out", "w");
	struct city C1, C2, Ci;
	int n, m, i, max = -1, distance;

	fscanf(f, "%d %d", &m, &n);
	fscanf(f, "%d %d", &C1.D, &C1.L);
	fscanf(f, "%d %d", &C2.D, &C2.L);
	for (i = 2; i < n; i++)
	{
		fscanf(f, "%d %d", &Ci.D, &Ci.L);
		distance = MAX_CITY(C1, C2, Ci);
		if (distance>max)
			max = distance;
	}
	fprintf(g, "%d", max);
	fclose(f);
	fclose(g);

}