Pagini recente » Cod sursa (job #866175) | Cod sursa (job #1488184) | Cod sursa (job #3285318) | Cod sursa (job #1352760) | Cod sursa (job #1447943)
#include <fstream>
#include <iostream>
using namespace std;
struct dreptunghi{
int xm, xM, ym, yM; };
constexpr int arie(const dreptunghi& d){
return (d.xm < d.xM && d.ym < d.yM) ? (d.xM-d.xm)*(d.yM-d.ym) : 0; }
constexpr int perimetru(const dreptunghi& d){
return (d.xm <= d.xM && d.ym < d.yM) ? 2*(d.xM-d.xm + d.yM-d.ym) : 0; }
dreptunghi intersect(const dreptunghi& a, const dreptunghi& b){
return dreptunghi{max(a.xm, b.xm), min(a.xM, b.xM), max(a.ym, b.ym), min(a.yM, b.yM)}; }
void validate(dreptunghi& dr){
if(dr.xm >= dr.xM || dr.ym >= dr.yM){
dr.xm = dr.xM = dr.ym = dr.yM = 0; } }
ifstream& operator>>(ifstream& f, dreptunghi& dr){
f >> dr.xm >> dr.ym >> dr.xM >> dr.yM;
return f; }
int main(){
ifstream f("reuniune.in");
dreptunghi a, b, c;
f >> a >> b >> c;
dreptunghi ab = intersect(a, b),
bc = intersect(b, c),
ac = intersect(a, c),
abc = intersect(ab, c);
validate(a);
validate(b);
validate(c);
validate(ab);
validate(ac);
validate(bc);
validate(abc);
ofstream g("reuniune.out");
g << arie(a) + arie(b) + arie(c) - arie(ab) - arie(bc) - arie(ac) + arie(abc) << ' ' <<
perimetru(a) + perimetru(b) + perimetru(c) - perimetru(ab) - perimetru(bc) - perimetru(ac)
+ perimetru(abc);
return 0; }