面向对象程序设计上机练习二(函数模板)
Time Limit: 1000MS
Memory Limit: 65536KB
Problem Description
利用数组和函数模板求5个数最大值(分别考虑整数、单精度、长整数的情况)。
Input
分别输入5个int型整数、5个float 型实数、5个long型正整数。
Output
分别输出5个int型整数的最大值、5个float 型实数的最大值、5个long型正整数的最大值。
Example Input
11 22 666 44 55 11.11 22.22 33.33 888.88 55.55 1234567 222222 333333 444444 555555
Example Output
666 888.88 1234567
Hint
Author
zlh
#include <iostream> ///适用于函数体和参数个数相同的函数
using namespace std;
template<typename T>
T Max(T a1,T a2,T a3,T a4,T a5)
{
if(a1<a2)
a1=a2;
if(a1<a3)
a1=a3;
if(a1<a4)
a1=a4;
if(a1<a5)
a1=a5;
return a1;
}
int main()
{
int a,b,c,d,e,f;
cin>>a>>b>>c>>d>>e;
f=Max(a,b,c,d,e);
double aa,bb,cc,dd,ee,ff;
cin>>aa>>bb>>cc>>dd>>ee;
ff=Max(aa,bb,cc,dd,ee);
long q,w,eee,r,t,y;
cin>>q>>w>>eee>>r>>t;
y=Max(q,w,eee,r,t);
cout<<f<<endl;
cout<<ff<<endl;
cout<<y<<endl;
}