AT1198_100 @ 2020-05-13 13:43:44
#include<bits/stdc++.h>
using namespace std;
int main(){
double a,b,c,d,e,f;
cin>>a>>b>>c>>d>>e>>f;
int x,y,z;
x=sqrt((c-a)*(c-a)+(d-b)*(d-b));
y=sqrt((e-c)*(e-c)+(f-d)*(f-d));
z=sqrt((e-a)*(e-a)+(f-b)*(f-b));
cout<<fixed<<setprecision(2)<<x+y+z;
return 0;
}
by kjy_ttcl @ 2020-05-13 13:45:28
@winterzxy 谁让你用int了?
by iMya_nlgau @ 2020-05-13 13:46:12
x,y,z 应该用double类型
by iMya_nlgau @ 2020-05-13 13:46:18
@winterzxy
by xhQYm @ 2020-05-13 13:46:30
改成这样:
#include<bits/stdc++.h>
using namespace std;
int main(){
double a,b,c,d,e,f;
cin>>a>>b>>c>>d>>e>>f;
double x,y,z;
x=sqrt((c-a)*(c-a)+(d-b)*(d-b));
y=sqrt((e-c)*(e-c)+(f-d)*(f-d));
z=sqrt((e-a)*(e-a)+(f-b)*(f-b));
cout<<fixed<<setprecision(2)<<x+y+z;
return 0;
}
by kjy_ttcl @ 2020-05-13 13:46:50
@qym2008 他xyz用的是int,输出的是整数,肯定不行
by xhQYm @ 2020-05-13 13:47:14
@kangjiayuan 刚刚我看错了,抱歉qwq
by AT1198_100 @ 2020-05-13 13:48:11
@Sapphire6575737973 谢谢
by kjy_ttcl @ 2020-05-13 13:48:19
不过直接用printf("%.2f)不是更方便吗?
by WanderingTrader @ 2020-05-13 14:46:39
@kangjiayuan 有的C++党就是想用setprecision
by kjy_ttcl @ 2020-05-13 14:49:59
@zycany 我谔谔