题目
使用重载函数模板重新可分别求取两个整数,三个整数,两个双精度数,三个双精度数的最大值
AC的C++代码如下:
#include<iostream>
#include<algorithm>
using namespace std;
template <class T>
T Max1(T a,T b){
return max(a,b);
}
template <class T>
T Max1(T a,T b,T c){
return max(max(a,b),c);
}
int main()
{
int x,y,z;
//两个整数
cout<<"Please enter two integer:\n";
cin>>x>>y;
cout<<Max1(x,y)<<endl;
//三个整数
cout<<"Please enter three integer:\n";
cin>>x>>y>>z;
cout<<Max1(x,y,z)<<endl;
double a,b,c;
//两个双精度数
cout<<"Please enter two double precision numbers:\n";
cin>>a>>b;
cout<<Max1(a,b)<<endl;
//三个双精度数
cout<<"Please enter three double precision numbers:\n";
cin>>a>>b>>c;
cout<<Max1(a,b,c)<<endl;
return 0;
}