64,636
社区成员
发帖
与我相关
我的任务
分享
#include <iostream>
#include<cstring>
using namespace std;
template<typename T>
T maxn ( T *a, const int n )
{
for ( int i = 0; i < n; i++ )
if ( a[i] > a[0] ) a[0] = a[i];
return a[0];
}
template<> const char* maxn( const char **a, const int n )
{
int i,j=0;
for(i=0;i<n;i++)
if(strlen(a[i])>strlen(a[j])) j=i;
return a[j];
}
int main()
{
int a[6] = {5, 7, 3, 6, 8, 0};
double b[4] = {1.1, 2.2, 0.1, 1.01};
const char *c[5] = {"Fuck", "Fuck you", "Fuck you now", "Fuck you and mother", "Fuck me"};
cout << maxn ( a, 6 ) << endl;
cout << maxn ( b, 4 ) << endl;
cout << maxn ( c, 5 ) << endl;
return 0;
}