Kyleshao @ 2023-01-13 11:23:51
源代码:
#include <bits/stdc++.h>
using namespace std;
struct zuobiao
{
int x,y;
};
double suan(int d1,int e1,int d2,int e2)
{
return sqrt((d2-d1)*(d2-d1)+(e2-e1)*(e2-e1));
}
zuobiao a[3];
int main()
{
for (int i=1;i<=3;i++)
{
cin>>a[i].x>>a[i].y;
}
int a1=suan(a[1].x,a[2].x,a[1].y,a[2].y);
int a2=suan(a[1].x,a[3].x,a[1].y,a[3].y);
int a3=suan(a[2].x,a[3].x,a[2].y,a[3].y);
printf("%.2f\n",a1+a2+a3);
return 0;
}
by WA_sir @ 2023-01-13 11:29:41
@Kyleshao 把 int 改成 double 试试
by Eleveslaine @ 2023-01-13 11:31:05
@Kyleshao
坐标均为实数且绝对值不超过
100 ,小数点后最多仅有3 位。
输入不一定是整数。
by Kyleshao @ 2023-01-13 11:35:01
@Franz_Liszt
#include <bits/stdc++.h>
using namespace std;
struct zuobiao
{
double x,y;
};
double suan(int d1,int e1,int d2,int e2)
{
return sqrt((d2-d1)*(d2-d1)+(e2-e1)*(e2-e1));
}
zuobiao a[3];
int main()
{
for (int i=1;i<=3;i++)
{
cin>>a[i].x>>a[i].y;
}
bool a1=suan(a[1].x,a[2].x,a[1].y,a[2].y);
bool a2=suan(a[1].x,a[3].x,a[1].y,a[3].y);
bool a3=suan(a[2].x,a[3].x,a[2].y,a[3].y);
printf("%.21f\n",a1+a2+a3);
return 0;
}
还是0分
by Eleveslaine @ 2023-01-13 11:35:50
@Kyleshao 您 suan
函数参数也没改成 double
啊
by Eleveslaine @ 2023-01-13 11:36:38
等等,参数都是乱的
by Eleveslaine @ 2023-01-13 11:41:41
@Kyleshao 啊啊啊这代码好乱啊
以下代码可以AC
#include <bits/stdc++.h>
using namespace std;
struct zuobiao
{
double x,y;
};
double suan(double d1,double e1,double d2,double e2)
{
return sqrt((d2-d1)*(d2-d1)+(e2-e1)*(e2-e1));
}
zuobiao a[4];
int main()
{
for(int i=1;i<=3;i++)
{
cin>>a[i].x>>a[i].y;
}
double a1=suan(a[1].x,a[1].y,a[2].x,a[2].y);
// 开什么bool啊,double好吧
double a2=suan(a[1].x,a[1].y,a[3].x,a[3].y);
double a3=suan(a[2].x,a[2].y,a[3].x,a[3].y);
printf("%.2lf\n",a1+a2+a3);
// %.2lf 不是 %.21f(字母l不是数字1)
return 0;
}