Oier_Yin @ 2020-11-02 14:38:07
#include<iostream>
#include<cstdio>
#include<cmath>
using namespace std;
struct xy
{
double x;
double y;
};
double longa(double a1,double b1,double a2,double b2)
{
return sqrt(pow(a1-b1,2)+pow(a2-b2,2));
}
int main()
{
double sum=0;
xy p[3];
for(int i=0;i<3;i++)
cin>>p[i].x>>p[i].y;
sum+=longa(p[0].x,p[0].y,p[1].x,p[1].y);
sum+=longa(p[0].x,p[0].y,p[2].x,p[2].y);
sum+=longa(p[1].x,p[1].y,p[2].x,p[2].y);
printf("%.2lf",sum);
return 0;
}
by A_Đark_Horcrux @ 2020-11-02 14:55:42
@Oier_Yin 看公式 横坐标和横坐标应该相减
double longa(double a1,double b1,double a2,double b2)
{
return sqrt(pow(a1-a2,2)+pow(b1-b2,2));
}
by Oier_Yin @ 2020-11-02 19:41:33
@A_Đark_Horcrux 谢谢大佬!
by Blood_red @ 2021-01-14 21:12:07
sqrt
#include <bits/stdc++.h>
using namespace std;
int main(){
double x1,y1,x2,y2,x3,y3,a,b,c;
cin>>x1>>y1>>x2>>y2>>x3>>y3;
a=sqrt((x2-x1)*(x2-x1)+(y2-y1)*(y2-y1));
b=sqrt((x3-x2)*(x3-x2)+(y3-y2)*(y3-y2));
c=sqrt((x1-x3)*(x1-x3)+(y1-y3)*(y1-y3));
printf("%.2f",a+b+c);
return 0;
}
AC