Pagini recente » Cod sursa (job #2203941) | Borderou de evaluare (job #1004025) | Cod sursa (job #1396584) | Cod sursa (job #1949889) | Cod sursa (job #2299216)
#include <fstream>
#include <iomanip>
#include <cmath>
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;
}
template <class T>
file_manip& operator >> (std::pair<T, T>& rhs) {
fin >> rhs.first >> rhs.second;
return *this;
}
};
#define MULT(a,b) (a.first * b.second - b.first * a.second)
int main()
{
file_manip fm("aria");
int N;
fm >> N;
using Point = std::pair<double, double>;
Point first, curr, next;
fm >> curr;
first = curr;
double area = 0.0;
while (--N)
{
fm >> next;
area += MULT(curr, next);
curr = next;
if (N == 1)
{
area += MULT(curr, first);
}
}
fm << std::fixed << std::setprecision(6) << std::fabs(area / 2);
return 0;
}