求助,为什么过不去qwq

P5735 【深基7.例1】距离函数

Stevehim @ 2022-09-04 20:05:34

#include <cstdio>
#include <cstring>
#include <iostream>
#include <cmath>
#include <algorithm>
#include <string>
using namespace std;

struct node {
    double x;
    double y;
} a[3];

int main() {
    for (int i = 0; i < 3; i++) {
        cin >> a[i].x >> a[i].y;
    }
    double d1, d2, d3;
    d1 = sqrt(pow(a[2].x - a[1].x, 2) + pow(a[2].y - a[1].y, 2));
    d2 = sqrt(pow(a[3].x - a[2].x, 2) + pow(a[3].y - a[2].y, 2));
    d3 = sqrt(pow(a[1].x - a[3].x, 2) + pow(a[1].y - a[3].y, 2));
    printf("%.2lf", d1 + d2 + d3);
    return 0;
}

by hhw_khw @ 2022-09-04 20:07:59

下面d1什么的a数组的下标应该从零开始,而非1


by Vanishing_Stars @ 2022-09-04 20:11:08

@Stevehim 楼上说的不错,我把你的代码修改了下,你直接贴就行


by Vanishing_Stars @ 2022-09-04 20:11:24

#include <cstdio>
#include <cstring>
#include <iostream>
#include <cmath>
#include <algorithm>
#include <string>
using namespace std;

struct node {
    double x;
    double y;
} a[3];

int main() {
    for (int i = 0; i < 3; i++) {
        cin >> a[i].x >> a[i].y;
    }
    double d1, d2, d3;
    d1 = sqrt(pow(a[1].x - a[0].x, 2) + pow(a[1].y - a[0].y, 2));
    d2 = sqrt(pow(a[2].x - a[1].x, 2) + pow(a[2].y - a[1].y, 2));
    d3 = sqrt(pow(a[0].x - a[2].x, 2) + pow(a[0].y - a[2].y, 2));
    printf("%.2lf", d1 + d2 + d3);
    return 0;
}

@Stevehim


by Stevehim @ 2022-09-04 20:15:39

@CODE_SUPERVISOR !!!!我真是个聪(大)明(智)人(慧)


by Stevehim @ 2022-09-04 20:16:26

@CODE_SUPERVISOR @hhw_khw 感谢二位!!!!


by Vanishing_Stars @ 2022-09-04 20:20:59

@Stevehim 不谢


|