c语言新生求指教
题目:
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;
}
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;
}
...全文
相关推荐
C语言-新生报到系统(完整版)
自学之后总结网上各路大神的代码想法,做出的完整版-C语言的课程设计--新生报到系统。
c语言求余数的实例讲解
c语言如何求余数? C语言中求余数直接用双目运算符%,如求a除以b的余数可表示为a%b 注意:C语言中的运算符%的两个操作数必须为整形,不能为浮点型或其他结构体类型,否则编译器会提示错误。 示例代码: #include int main() { int a=5, b=3, c; c=a%b; //将a除以b的余数赋值给c printf("%d",c); return 0; } /* 输出:2 */ 知识点补充: C语言求余数问题 C语言里对于有一些符号是不能直接输出的,因为被C语言占用了。所以有一些符号是需要特殊的方式才能输出的。比如你说的%号,%
求两点距离(C语言)
程序实现求两点距离,C语言入门程序,C语言课程数字计算类小练习。
c语言实现矩阵求逆程序
c实现矩阵求逆程序。希望对大家有所帮助。
求和 求平均数——C语言代码
课程的随堂作业,C语言的,用dev就能运行,萌新代码,勿喷,仅仅帮助不想写作业的朋友方便一下,反正老师也不会仔细检查的


