[ create a new paste ] login | about

Link: http://codepad.org/1iCA3pbb    [ raw code | output | fork ]

C++, pasted on Jun 25:
#include <cstdlib>
#include <iostream>

///
template <typename T>
T func_max(T arr[], int count)
{ 
    T Res = arr[0];
    for(int i = 0; i < count; ++i)
        if(arr[i] > Res)
			Res = arr[i];
	return Res;
}

template <> 
const char *func_max(const char *cArr[], int count)
{  
	const char *Res = cArr[0];
	for(int i = 0; i < count; ++i)
		if(strlen(Res) < strlen(cArr[i]))
            Res = cArr[i];    
	return Res;
}

int main(int argc, char *argv[])
{
    int		mass1[6] = { 5, 90, 3, 2, 9, 7	};
	double	mass2[4] = { 4.8, 8.0, 5.3, 3.14};
	const char *mchar[5] = 
	{
		"Dasha",
		"InokentyW",
		"Jora",
		"Tanyasdw",
		"IrinaW"
	};

    std::cout << func_max(mass1,6) << std::endl;
	std::cout << func_max(mass2,4) << std::endl;
	std::cout << func_max(mchar,5) << std::endl;

    system("PAUSE");
    return EXIT_SUCCESS;
}


Output:
1
2
3
4
5
90
8
InokentyW

Disallowed system call: SYS_fork


Create a new paste based on this one


Comments: