equipy_rrt @ 2023-11-26 14:43:17
#include<iostream>
#include<cmath>
using namespace std;
struct place{
float x,y;
} pot[5];
float squ(float x){
return pow(x,2);
}
float dis(float a,float b,float c,float d){
return sqrt(squ(a-b)+squ(c-d));
}
int main(){
float ans=0;
for(int i=1;i<=3;i++) cin>>pot[i].x>>pot[i].y;
ans+=dis(pot[2].x,pot[1].x,pot[2].y,pot[1].y);
ans+=dis(pot[3].x,pot[2].x,pot[3].y,pot[2].y);
ans+=dis(pot[3].x,pot[1].x,pot[3].y,pot[1].y);
cout<<ans;
return 0;
}
by FurippuWRY @ 2023-11-26 14:44:17
为什么要用结构体
by NaCl_0_9H2O @ 2023-11-26 14:45:19
//ac
#include<bits/stdc++.h>
using namespace std;
double dis(double a,double b,double c,double d)
{
double a1=sqrt((c-a)*(c-a)+(d-b)*(d-b));
return a1;
}
int main()
{
double x1,x2,y1,y2,z1,z2,sum=0;
cin>>x1>>x2>>y1>>y2>>z1>>z2;
sum+=dis(x1,x2,y1,y2);
sum+=dis(x1,x2,z1,z2);
sum+=dis(z1,z2,y1,y2);
cout<<fixed<<setprecision(2)<<sum;
return 0;
}
副:好像用不着结构体
by equipy_rrt @ 2023-11-26 14:52:25
我只想知道错在哪里而已······
by Find_NICK @ 2023-11-26 14:58:14
float精度问题