CR7syn @ 2022-11-23 15:30:37
#include<stdio.h>
#include<string.h>
#include<math.h>
typedef struct date {
float a;
float b;
}node;
int main()
{
int i;
int c;
int e;
double dis=0;
node d[3];
scanf("%f %f", &d[0].a, &d[0].b);
scanf("%f %f", &d[1].a, &d[1].b);
scanf("%f %f", &d[2].a, &d[2].b);
for (i = 0; i < 3; i++)
{
c = d[i % 3].a - d[(i + 1) % 3].a;
e = d[i % 3].b - d[(i + 1) % 3].b;
dis += sqrt(c * c + e * e);
}
printf("%.2lf", dis);
}
by NightStriker @ 2022-11-23 15:48:48
@CR7syn 看看是否需要 double
/ long long
等数据类型。
by CR7syn @ 2022-11-23 15:56:51
@ljp 我把数据类型都改成double了,还是会出现一个wa
by ChampionYoung @ 2022-11-23 16:11:09
@CR7syn 能发下改之后的代码吗
by ChampionYoung @ 2022-11-23 16:16:40
@CR7syn 不用了, int c, e
改成 double c, e
by liuzr156 @ 2022-11-23 16:32:12
@CR7syn 两个地方第一把除了i之外全改成double类型
第二输入改成scanf("%lf %lf", &d[i].a, &d[i].b);
最后附赠亲手改的
#include<stdio.h>
#include<string.h>
#include<math.h>
typedef struct date {
double a;
double b;
}node;
int main()
{
int i;
double c;
double e;
double dis=0;
node d[4];
scanf("%lf %lf", &d[0].a, &d[0].b);
scanf("%lf %lf", &d[1].a, &d[1].b);
scanf("%lf %lf", &d[2].a, &d[2].b);
for (i = 0; i < 3; i++)
{
c = d[i % 3].a - d[(i + 1) % 3].a;
e = d[i % 3].b - d[(i + 1) % 3].b;
dis += sqrt(c * c + e * e);
}
printf("%.2lf", dis);
}
by CR7syn @ 2022-11-23 17:30:37
谢谢各位了,眼瞎了不好意思