#30. 数组首尾中最大值
数组首尾中最大值
Max of First, Last, and Middle
Background
Congcong is learning basic array operations. He encountered a problem where he needs to find the largest element among specific positions in a given array.
Problem Description
Given an array of integers of odd length, examine the first, last, and middle values in the array and return the largest among them. The array length will be at least .
Input Format
Input is given from standard input in the following format.
An array of integers, e.g.,
[1 2 3]. Elements are space-separated.
Output Format
Output is printed to standard output in the following format.
An integer, representing the maximum value among the first, last, and middle elements.
Sample
[1 2 3]
3
[1 5 3]
5
[5 2 3]
5
Sample Explanation
For Sample 1, the array is [1 2 3]. The first element is , the last element is , and the middle element is . The maximum value among them is .
For Sample 2, the array is [1 5 3]. The first element is , the last element is , and the middle element is . The maximum value among them is .
For Sample 3, the array is [5 2 3]. The first element is , the last element is , and the middle element is . The maximum value among them is .
Constraints
Time limit: second. Memory limit: MiB for each test case.