杭电 2056 Rectangles

http://acm.hdu.edu.cn/showproblem.php?pid=2056

#include<stdio.h>
void swap(double *x,double *y){
	double t;
	t = *x;
	*x = *y;
	*y = t;
}

int main()
{
	double x1,x2,x3,x4,y1,y2,y3,y4,x5,y5,x6,y6;
	while(scanf("%lf%lf%lf%lf%lf%lf%lf%lf",&x1,&y1,&x2,&y2,&x3,&y3,&x4,&y4) != EOF)//必须有l
	{
		if(x1>x2)swap(&x1,&x2);
	    if(y1>y2)swap(&y1,&y2);
	    if(x3>x4)swap(&x3,&x4);
	    if(y3>y4)swap(&y3,&y4);
		x5 = x1>x3?x1:x3;
		y5 = y1>y3?y1:y3;
        x6 = x2>x4?x4:x2;        
        y6 = y2>y4?y4:y2;		
		//printf("%.2lf\n",x6 >= x5 && y6 >= y5?(x6-x5)*(y6-y5):0);
		if(x6 > x5 && y6 > y5) printf("%.2f\n",(x6-x5)*(y6-y5)); 
		else printf("0.00\n");
	}
	return 0;
}

(1)对于double的输入必须是lf,输出没有要求;

(2)交换两个数的值是用变量来交换,不是指针;

(3)横坐标小,纵坐标不一定小(错误认为交换横坐标就一定交换其纵坐标)。

猜你喜欢

转载自blog.csdn.net/u012102588/article/details/18951535