final函数模板
#include<iostream>
#include<cmath>
using namespace std;
class Point{
private:
double x;
double y;
double z;
public:
Point(double a,double b,double c):x(a),y(b),z(c){};
friend double operator-(Point,Point);
};
template<class T>
double dist(T a,T b){
return abs(a-b);
}
double operator-(Point P1,Point P2){
return sqrt(pow(P1.x-P2.x,2)+pow(P1.y-P2.y,2)+pow(P1.z-P2.z,2));
}
int main()
{
int i,j;
float p,q;
double x1,y1,z1,x2,y2,z2;
int flag;
while(1){
cin>>flag;
if(flag==0){
break;
}
if(flag==1){
cin>>i>>j;
cout<<dist(i,j)<<endl;
}else if(flag==2){
cin>>p>>q;
cout<<dist(p,q)<<endl;
}else{
cin>>x1>>y1>>z1>>x2>>y2>>z2;
Point P1(x1,y1,z1),P2(x2,y2,z2);
cout<<dist(P1,P2)<<endl;
}
}
return 0;
}