Given two rectangles and the coordinates of two points on the diagonals of each rectangle,you have to calculate the area of the intersected part of two rectangles. its sides are parallel to OX and OY .
1.00 1.00 3.00 3.00 2.00 2.00 4.00 4.00 5.00 5.00 13.00 13.00 4.00 4.00 12.50 12.50
1.00 56.25
#include<stdio.h>
double max(double m, double n);
double min(double m, double n);
int main()
{
double x[5], y[5], area, t;
int i, flag, j;
while(scanf("%lf%lf%lf%lf%lf%lf%lf%lf", &x[1], &y[1], &x[2], &y[2], &x[3], &y[3], &x[4], &y[4])!=EOF)
{
flag=0;
if(max(x[1], x[2])<min(x[3], x[4]) || max(x[3], x[4])<min(x[1], x[2]) || max(y[1], y[2])<min(y[3], y[4]) || max(y[3], y[4])<min(y[1], y[2]))
flag=1;
for(i=1;i<4;i++)
for(j=i+1;j<5;j++)
if(x[i]>x[j])
{t=x[i];x[i]=x[j];x[j]=t;}
for(i=1;i<4;i++)
for(j=i+1;j<5;j++)
if(y[i]>y[j])
{t=y[i];y[i]=y[j];y[j]=t;}
if(flag)
area=0;
else
area=(x[3]-x[2])*(y[3]-y[2]);
printf("%.2lf\n", area);
}
return 0;
}
double max(double m, double n)
{
m=m>n?m:n;
return m;
}
double min(double m, double n)
{
m=m>n?n:m;
return m;
}