Pagini recente » Cod sursa (job #2141290) | Cod sursa (job #2777804) | Cod sursa (job #2702591) | Cod sursa (job #1682665) | Cod sursa (job #1781592)
#include <iostream>
#include <fstream>
#include <vector>
using namespace std;
ifstream in("reuniune.in");
ofstream out("reuniune.out");
class Dreptunghi
{
private:
long x1;
long y1;
long x2;
long y2;
public:
Dreptunghi(){};
Dreptunghi(long x1, long y1, long x2, long y2)
{
this->x1 = x1;
this->y1 = y1;
this->x2 = x2;
this->y2 = y2;
}
friend istream& operator>>(istream &in, Dreptunghi &dreptunghi)
{
in>> dreptunghi.x1 >> dreptunghi.y1>> dreptunghi.x2>> dreptunghi.y2;
return in;
}
long Arie()
{
return (x2 - x1) * (y2 - y1);
}
long Perimetru()
{
return 2 * (x2 - x1 + y2 - y1);
}
long GetX1()
{
return x1;
}
long GetY1()
{
return y1;
}
long GetX2()
{
return x2;
}
long GetY2()
{
return y2;
}
};
class Intersectie
{
public:
Dreptunghi IntersectieDreptunghiuri(Dreptunghi dreptunghi1, Dreptunghi dreptunghi2 )
{
Dreptunghi dreptunghi( max(dreptunghi1.GetX1(), dreptunghi2.GetX1()),
max(dreptunghi1.GetY1(), dreptunghi2.GetY1()),
min(dreptunghi1.GetX2(), dreptunghi2.GetX2()),
min(dreptunghi1.GetY2(), dreptunghi2.GetY2())
);
if( dreptunghi.GetX1() > dreptunghi.GetX2() || dreptunghi.GetY1() > dreptunghi.GetY2() )
{
Dreptunghi dreptunghiAux(0, 0, 0, 0);
dreptunghi = dreptunghiAux;
}
return dreptunghi;
}
};
int main()
{
int aria = 0;
int perimetru = 0;
Dreptunghi dreptunghi(0, 0, 0, 0);
Intersectie intersectie;
vector<Dreptunghi> dreptunghiuri(3, dreptunghi);
for( int i = 0; i<3; ++i )
{
in>> dreptunghiuri[i];
aria += dreptunghiuri[i].Arie();
perimetru += dreptunghiuri[i].Perimetru();
}
for( int i = 0; i<2; ++i )
{
for( int j = i + 1; j<3; ++j )
{
dreptunghi = intersectie.IntersectieDreptunghiuri(dreptunghiuri[i], dreptunghiuri[j]);
aria -= dreptunghi.Arie();
perimetru -= dreptunghi.Perimetru();
}
}
dreptunghi = intersectie.IntersectieDreptunghiuri(
intersectie.IntersectieDreptunghiuri( dreptunghiuri[0], dreptunghiuri[1]),
dreptunghiuri[2] );
aria += dreptunghi.Arie();
perimetru += dreptunghi.Perimetru();
out<< aria<<" "<< perimetru;
in.close();
out.close();
return 0;
}