c语言新生求指教

huee812 huee812 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
题目:
Description
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 .
Input
Input The first line of input is 8 positive numbers which indicate the coordinates of four points that must be on each diagonal.The 8 numbers are x1,y1,x2,y2,x3,y3,x4,y4.That means the two points on the first rectangle are(x1,y1),(x2,y2);the other two points on the second rectangle are (x3,y3),(x4,y4).
Output
Output For each case output the area of their intersected part in a single line.accurate up to 2 decimal places.
Sample Input
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
Sample Output
1.00
56.25

问题:oj上交是0分

#include<stdio.h>
#include<math.h>
int main()
{
double x1,y1,x2,y2,x3,y3,x4,y4,a[4],b[4];
int i,j,t1,t2,t3,t4,t5,t6;
double s;
while(scanf("%lf%lf%lf%lf%lf%lf%lf%lf",&x1,&y1,&x2,&y2,&x3,&y3,&x4,&y4)!=EOF){
double a[4]={x1,x2,x3,x4};
double b[4]={y1,y2,y3,y4};
t1=t2=t3=t4=0;
for(i=0;i<3;i++){if(b[t1]>b[i+1]) t1=i+1;}//xiao
for(i=0;i<3;i++){if(b[t2]<b[i+1]) t2=i+1;}//da
for(i=0;i<=3;i++){if(b[i]<b[t2]&&i!=t1) t3=i;}
for(i=3;i>=0;i--){if(b[i]<b[t2]&&i!=t1) t4=i;}
t5=t3;t6=t4;
t1=t2=t3=t4=0;
for(i=0;i<3;i++){if(a[t1]>a[i+1]) t1=i+1;}//xiao
for(i=0;i<3;i++){if(a[t2]<a[i+1]) t2=i+1;}//da
for(i=0;i<=3;i++){if(a[i]<a[t2]&&i!=t1) t3=i;}
for(i=3;i>=0;i--){if(a[i]<a[t2]&&i!=t1) t4=i;}
s=(fabs(a[t3]-a[t4]))*(fabs(b[t5]-b[t6]));
if(a[1]<a[2]) printf("0\n");
else printf("%.2lf\n",s);
}
return 0;
}

...全文

相关推荐

评论 2
收藏 已收藏
分享
返回顶部
huee812
C语言 70,039 成员 243,237 内容