In this problem, you are required to implement four template functions: Reverse
, Minimum
, Maximum
, and Average
.
template <typename T> void Reverse(T *const base, size_t n);
function takes a pointer to the first element of an array and the size of the array. It reverses the array in place.template <typename T> T Minimum(T const *const base, size_t n);
function takes a pointer to the first element of an array and the size of the array. It returns the minimum element(with respect to the <
operator) in the array.template <typename T> T Maximum(T const *const base, size_t n);
function takes a pointer to the first element of an array and the size of the array. It returns the maximum element(with respect to the <
operator) in the array.template <typename T> T Average(T const *const base, size_t n);
function takes a pointer to the first element of an array and the size of the array. It returns the average of the elements in the array. If T
is an integer/character/boolean type, round down the result. If T
is a string type, return a string that contains one character, which is the sum of all the characters in all strings, divided by the sum of string length.Note: You shouldn't modify the original array in the Minimum
, Maximum
, and Average
functions.
This line of code might come in handy...
template <>
std::string Average(std::string const *const base, size_t n)
main
.The first line contains an integer n
\((1 \le n \le 5 \times 10^4)\), the size of each array.
The second line contains n
integers, the elements of the array \(a\) (\(-10^9 \le a_i \le 10^9\)).
The third line contains n
integers, the elements of the array \(b\) (\(0 \le b_i \le 1\)).
The fourth line contains n
characters, the elements of the array \(c\) (\(c_i\) is a lowercase letter).
The fifth line contains n
strings, the elements of the array \(d\) (\(1 \le |d_i| \le 10^5\)).
\(n\)
\(a_1 \quad a_2 \quad \cdots \quad a_n\)
\(b_1 \quad b_2 \quad \cdots \quad b_n\)
\(c_1 \quad c_2 \quad \cdots \quad c_n\)
\(d_1 \quad d_2 \quad \cdots \quad d_n\)
main
.