Cod sursa(job #1779266)

Utilizator andreioneaAndrei Onea andreionea Data 14 octombrie 2016 23:55:07
Problema Aria Scor 10
Compilator cpp Status done
Runda Arhiva educationala Marime 0.98 kb
#include <fstream>
#include <iomanip>

struct file_manip {

	std::ifstream fin;
	std::ofstream fout;

	file_manip(const char* filename) {
		std::string infilename  = std::string(filename) + ".in";
		std::string outfilename = std::string(filename) + ".out";
		fin.open(infilename.c_str());
		fout.open(outfilename.c_str());
	}

	template <class T>
	file_manip& operator << (const T& rhs) {
		fout << rhs;
		return *this;
	}
	template <class T>
	file_manip& operator >> (T& rhs) {
		fin >> rhs;
		return *this;
	}

};


int main()
{
	file_manip fm("aria");
	int N;
	fm >> N;
	using Point = std::pair<float, float>;
	Point first, curr, next;
	fm >> curr.first >> curr.second;
	first = curr;
	double area = 0.0;
	while (--N)
	{
		fm >> next.first >> next.second;
		area += curr.first * next.second - next.first * curr.second;
		curr = next;
		if (N == 1)
		{
			next = first;
			area += curr.first * next.second - next.first * curr.second;
		}
	}
	fm << std::setprecision(5) << area * 0.5;
	return 0;	
}