lirenzehao @ 2023-11-09 19:34:04
#include<bits/stdc++.h>
using namespace std;
double x[5],y[5],sum;
int f(int a){
return a*a;
}
void init(){
for(int i=1;i<=3;i++){
cin>>x[i]>>y[i];
}
}
void j(){
for(int i=2;i<=3;i++){
for(int j=1;j<i;j++){
sum+=sqrt(f(x[i]-x[j])+f(y[i]-y[j]));
}
}
}
int main(){
init();
j();
printf("%.2lf",sum);
}
by penguin_is_cool @ 2023-11-09 19:58:50
#include <iostream>
#include <cmath>
using namespace std;
int main(){
double x1,x2,x3,y1,y2,y3,a,b,c;
double sum=0.0;
cin>>x1>>y1>>x2>>y2>>x3>>y3;
a=abs(sqrt(abs(pow(abs(x2-x1),2))+abs(pow(abs(y2-y1),2))));
b=abs(sqrt(abs(pow(abs(x3-x1),2))+abs(pow(abs(y3-y1),2))));
c=abs(sqrt(abs(pow(abs(x3-x2),2))+abs(pow(abs(y3-y2),2))));
sum=sum+a+b+c;
printf("%.2f",sum);
}
不用函数也行
我其实函数都不会
by penguin_is_cool @ 2023-11-09 19:59:38
@lirenzehao 其实还要绝对值abs
by lirenzehao @ 2023-11-09 20:02:34
@penguin_is_cool 谢谢,问题已解决
by sbno333 @ 2023-11-09 20:07:47
#include<bits/stdc++.h>
using namespace std;
double x[5],y[5],sum;
double f(double a){//不开double建祖宗
return a*a;
}
void init(){
for(int i=1;i<=3;i++){
cin>>x[i]>>y[i];
}
}
void j(){
for(int i=2;i<=3;i++){
for(int j=1;j<i;j++){
sum+=sqrt(f(x[i]-x[j])+f(y[i]-y[j]));
}
}
}
int main(){
init();
j();
printf("%.2lf",sum);
}