dlklwdc @ 2022-08-21 09:23:14
如下
#include <bits/stdc++.h>
using namespace std;
int a1,a2,b1,b2,c1,c2;
double a;
int jisuan(int a,int aa,int b,int bb){//sqrt[(b-a)*(b-a)+(bb-aa)*(bb-aa)]
double q=abs(sqrt(abs((b-a)*(b-a))+abs((bb-aa)*(bb-aa))));
return q;
}
int main()
{
freopen("P5735.in","r",stdin);
freopen("P5735.out","w",stdout);
cin>>a1>>a2;
cin>>b1>>b2;
cin>>c1>>c2;
a=abs(jisuan(a1,a2,b1,b2))+abs(jisuan(a1,a2,c1,c2))+abs(jisuan(b1,b2,c1,c2));
printf("%0.2lf",a);
fclose(stdin);
fclose(stdout);
}
by _Haoomff_ @ 2022-08-21 09:24:31
freopen……
by dlklwdc @ 2022-08-21 09:28:32
。。。。。我忘了。。。。。 我是个sb
by dlklwdc @ 2022-08-21 09:30:43
可还是0分。。。
by Chenyichen0420 @ 2022-08-21 10:03:38
int jisuan(...),return 的一定是int型,而你想要的是double型
by Chenyichen0420 @ 2022-08-21 10:08:27
应该是AC代码:
#include<iostream>
#include<algorithm> //万能头文件OK
using namespace std;
int a1, a2, b1, b2, c1, c2; double ans;
double jisuan(int x1, int x2, int y1, int y2) {
double q = sqrt((x2 - x1)*(x2 - x1) + (y2 - y1)*(y2 - y1));
return q;
}
int main(){
cin >> a1 >> a2;
cin >> b1 >> b2;
cin >> c1 >> c2;
ans = jisuan(a1, a2, b1, b2) + jisuan(a1, a2, c1, c2) + jisuan(b1, b2, c1, c2);
printf("%.2lf", ans);
return 0;
}
by Chenyichen0420 @ 2022-08-21 10:09:58
不好意思,少一个cmath头文件
by Chenyichen0420 @ 2022-08-21 10:17:57
更正:
#include<iostream>
#include<cmath>
using namespace std;
int main(){
double x1, y1, x2, y2, x3, y3, ans;
cin >> x1 >> y1 >> x2 >> y2 >> x3 >> y3;
ans = sqrt((x1 - x2)*(x1 - x2) + (y1 - y2)*(y1 - y2)) + sqrt((x2 - x3)*(x2 - x3) + (y2 - y3)*(y2 - y3)) + sqrt((x1 - x3)*(x1 - x3) + (y1 - y3)*(y1 - y3));
printf("%.2lf\n", ans);
return 0;
}
x,y值也应该为double型。
by dlklwdc @ 2022-08-29 22:10:55
谢谢带佬!