zlh202483023 @ 2024-11-26 11:27:07
#include<iostream>
#include<iomanip>
#include<cmath>
using namespace std;
float dis(int a, int b, int c, int d);
int main() {
int x1, x2, y1, y2, x3, y3;
double a,b,c,sum;
cin >> x1 >> y1 >> x2 >> y2 >> x3 >> y3;
a = dis(x1, y1, x2, y2);
b = dis(x1, y1, x3, y3);
c = dis(x2, y2, x3, y3);
sum=a + b + c;
cout << fixed << setprecision(2) << sum;
}
float dis(int a, int b,int c,int d) {
float distant;
distant = sqrt((a - c) * (a - c) + (b - d) * (b - d));
return distant;
}
by xiaoyu2009 @ 2024-11-26 21:34:15
用double 我就是用int80
double就a了
还有不要把定义放外面
因为变量名会和函数重 会CE
#include<bits/stdc++.h>
using namespace std;
double sum;
int main()
{
double x1,x2,x3,y1,y2,y3;
cin>>x1>>y1>>x2>>y2>>x3>>y3;
sum+=sqrt((x2-x1)*(x2-x1)+(y2-y1)*(y2-y1));
sum+=sqrt((x3-x2)*(x3-x2)+(y3-y2)*(y3-y2));
sum+=sqrt((x3-x1)*(x3-x1)+(y3-y1)*(y3-y1));
printf("%.2lf",sum);
return 0;
}