level 2
flexrica07
楼主
#include<iostream>
#include<iomanip>
#include<algorithm>
using namespace std;
double paixu(double a,double b,double c,double d){
double t[4]={a,b,c,d};//一开始忘记给数组赋值了 。
for(int i=0;i<4;i++)
{
for(int j=i+1;j<4;j++)//遍历
{
if(t[i]<=t[j])
{
double temp=0;
temp=t[i];
t[i]=t[j];
t[j]=temp;//交换
}
}
}
return (t[1]-t[2]);
}
int main()
{
double x1,y1,x2,y2,x3,y3,x4,y4;
double S=0;
cin>>x1>>y1>>x2>>y2>>x3>>y3>>x4>>y4;
if(std::max(x1,x2)<=std::min(x3,x4)||std::max(y1,y2)<=std::min(y3,y4)||std::max(x3,x4)<=std::min(x1,x2)||std::max(y3,y4)<=std::min(y1,y2))
{
cout<<"0.00"<<endl;//二者不相交,注意考虑二者互换考虑
}
else
{
double length=0;
double width=0;
length=paixu(x1,x2,x3,x4);
width=paixu(y1,y2,y3,y4);
S=length*width;
cout<<fixed<<setprecision(2)<<S<<endl;
}
return 0;
}
2025年10月02日 08点10分
1
#include<iomanip>
#include<algorithm>
using namespace std;
double paixu(double a,double b,double c,double d){
double t[4]={a,b,c,d};//一开始忘记给数组赋值了 。
for(int i=0;i<4;i++)
{
for(int j=i+1;j<4;j++)//遍历
{
if(t[i]<=t[j])
{
double temp=0;
temp=t[i];
t[i]=t[j];
t[j]=temp;//交换
}
}
}
return (t[1]-t[2]);
}
int main()
{
double x1,y1,x2,y2,x3,y3,x4,y4;
double S=0;
cin>>x1>>y1>>x2>>y2>>x3>>y3>>x4>>y4;
if(std::max(x1,x2)<=std::min(x3,x4)||std::max(y1,y2)<=std::min(y3,y4)||std::max(x3,x4)<=std::min(x1,x2)||std::max(y3,y4)<=std::min(y1,y2))
{
cout<<"0.00"<<endl;//二者不相交,注意考虑二者互换考虑
}
else
{
double length=0;
double width=0;
length=paixu(x1,x2,x3,x4);
width=paixu(y1,y2,y3,y4);
S=length*width;
cout<<fixed<<setprecision(2)<<S<<endl;
}
return 0;
}