Cod sursa(job #1442206)

Utilizator aokirisakiLisca Ana aokirisaki Data 24 mai 2015 17:50:20
Problema Reuniune Scor 30
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.33 kb
#include <cstdlib>
#include <cstdio>
using namespace std;

struct point{double x,y;};

struct drept{point st,dr;};

 drept d1,d2,d3;

drept interior(drept d1,drept d2)
{drept d3;
    if(d1.st.x>d2.st.x)
    d3.st.x=d1.st.x;
    else d3.st.x=d2.st.x;
    if(d1.st.y>d2.st.y)
    d3.st.y=d1.st.y;
    else d3.st.y=d2.st.y;
    if(d1.dr.x<d2.dr.x)
    d3.dr.x=d1.dr.x;
    else d3.dr.x=d2.dr.x;
    if(d1.dr.y<d2.dr.y)
    d3.dr.y=d1.dr.y;
    else d3.dr.y=d2.dr.y;

  return d3;
}

double arie_drept(drept d)
{
    return ((d.dr.x-d.st.x)*(d.dr.y-d.st.y));
}

double perimetru_drept(drept d)
{
    return 2*(d.dr.x-d.st.x+d.dr.y-d.st.y);
}

int main()
{
 drept a,b,c,d;
     freopen("reuniune.in","r",stdin);
	freopen("reuniune.out", "w", stdout);
    scanf("%lf%lf%lf%lf",&d1.st.x,&d1.st.y,&d1.dr.x,&d1.dr.y);
    scanf("%lf%lf%lf%lf",&d2.st.x,&d1.st.y,&d2.dr.x,&d2.dr.y);
    scanf("%lf%lf%lf%lf",&d3.st.x,&d3.st.y,&d3.dr.x,&d3.dr.y);
    a=interior(d1,d2);
    b=interior(d1,d3);
    c=interior(d2,d3);
    d=interior(a,d3);
    printf("%.0f ",arie_drept(d1)+arie_drept(d2)+arie_drept(d3)-arie_drept(a)-arie_drept(b)-arie_drept(c)+arie_drept(d));
    printf("%.0f",perimetru_drept(d1)+perimetru_drept(d2)+perimetru_drept(d3)-perimetru_drept(a)-perimetru_drept(b)-perimetru_drept(c)+perimetru_drept(d));
}