c语言新生求指教

huee812 2019-12-15 01:31:01
题目:
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;
}

...全文
60 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
寻开心 2019-12-15
  • 打赏
  • 举报
回复
#include<stdio.h>
int main()
{
float x1,y1,x2,y2,x3,y3,x4,y4;
while(scanf("%f%f%f%f%f%f%f%f", &x1, &y1, &x2, &y2, &x3, &y3, &x4, &y4)!=EOF) {
float u1, u2, v1, v2;
u1 = min ( max(x1,x2), max(x3,x4));
v1 = min ( max(y1,y2), max(y3,y4));
u2 = max ( min(x1,x2), min(x3,x4));
v2 = max ( min(y1,y2), min(y3,y4));
if ( u1<u2 || v1<v2 )
printf("0\n");
else
printf("%.2f\n", (u2-u1)*(v2-v1));
}
return 0;
}
遇见女神 2019-12-15
  • 打赏
  • 举报
回复
是只输入8个数字,while循环不合适吧。

69,369

社区成员

发帖
与我相关
我的任务
社区描述
C语言相关问题讨论
社区管理员
  • C语言
  • 花神庙码农
  • 架构师李肯
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧