样例过了,但全错,哪位大佬能帮忙解释一下?

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

朱雯萱 @ 2021-01-27 21:35:59

#include<iostream>
#include<cstdio>
#include<cmath>
using namespace std;
int a(double x1,double y1,double x2,double y2){
    return sqrt(abs((x2-x1)*(x2-x1))+abs((y2-y1)*(y2-y1)));
}
int main(){
    double x1,x2,x3,y1,y2,y3;
    cin>>x1>>y1>>x2>>y2>>x3>>y3;
    double s=a(x1,y1,x2,y2),l=a(x2,y2,x3,y3),h=a(x3,y3,x1,y1);
    printf("%.2f",s+l+h);
    return 0;
} 

by konjacq @ 2021-01-27 21:38:26

@朱雯萱 换成printf("%.2lf",s+l+h);试试?


by _caiji_ @ 2021-01-27 21:39:07

int a(double x1,double y1,double x2,double y2)

改成

double a(double x1,double y1,double x2,double y2)

试试看


by 朱雯萱 @ 2021-01-27 21:39:33

@konjacq 也不对


by CGDGAD @ 2021-01-27 21:40:43

好不容易算完 sqrt 然后您返回类型为 int


by 朱雯萱 @ 2021-01-27 21:41:44

@NSObject ?


by jyb666 @ 2021-01-27 21:41:53

int double a(double x1,double y1,double x2,double y2)


by jyb666 @ 2021-01-27 21:42:28

@朱雯萱 NSObject指函数返回值


by 朱雯萱 @ 2021-01-27 21:43:42

@jyb666 谢谢


by 朱雯萱 @ 2021-01-27 21:44:01

@NSObject 谢谢您


by _caiji_ @ 2021-01-27 22:07:11

我被lz屏蔽了吗,就2楼那么显眼的位置都看不到


|