Cod sursa(job #1798306)

Utilizator Etienne27Stefan Etienne27 Data 5 noiembrie 2016 09:48:17
Problema Aria Scor 70
Compilator cpp Status done
Runda Arhiva educationala Marime 0.66 kb
#define _CRT_SECURE_NO_WARNINGS
#include <fstream>
FILE* fin = fopen("aria.in","r");
FILE* fout = fopen("aria.out", "w");
struct Point
{
	double x, y;
};

double computeArea(Point p1, Point p2)
{
	return p1.x*p2.y - p2.x*p1.y;
}

int main()
{
	double area = 0.0;
	int nrOfPoints;
	Point current,previous,first;
	fscanf(fin, "%d", &nrOfPoints);

	fscanf(fin, "%lf %lf", &previous.x, &previous.y);
	first = previous;
	for (int i = 1; i < nrOfPoints; i++)
	{
		fscanf(fin, "%lf %lf", &current.x,&current.y);
		area += computeArea(previous, current);
		previous = current;
	}
	area += computeArea(previous, first);
	fprintf(fout,"%lf", area/2.0);
}