Pagini recente » Cod sursa (job #2950606) | Cod sursa (job #468186) | Cod sursa (job #520738) | Cod sursa (job #3324392) | Cod sursa (job #3358781)
#include <fstream>
#include <cmath>
using namespace std;
ifstream f("reuniune.in");
ofstream g("reuniune.out");
struct dreptunghi
{
int x1, y1, x2, y2, arie, perim;
};
dreptunghi d1, d2, d3, d12, d23, d13, dtotal;
void citire(dreptunghi &d)
{
f>>d.x1>>d.y1>>d.x2>>d.y2;
}
void calcul(dreptunghi &d)
{
d.arie=abs(d.x1-d.x2)*abs(d.y1-d.y2);
d.perim=(abs(d.x1-d.x2)+abs(d.y1-d.y2))*2;
}
void intersectie(dreptunghi a, dreptunghi b, dreptunghi &c)
{
c.x1=max(a.x1, b.x1);
c.y1=max(a.y1, b.y1);
c.x2=min(a.x2, b.x2);
c.y2=min(a.y2, b.y2);
calcul(c);
}
int main()
{
citire(d1);
calcul(d1);
citire(d2);
calcul(d2);
citire(d3);
calcul(d3);
intersectie(d1,d2,d12);
intersectie(d2,d3,d23);
intersectie(d1,d3,d13);
intersectie(d12,d13,dtotal);
g << d1.arie + d2.arie + d3.arie - d12.arie - d23.arie - d13.arie + dtotal.arie << ' '
<< d1.perim + d2.perim + d3.perim - d12.perim - d23.perim - d13.perim + dtotal.perim;
return 0;
}