#70. 计算中心平均数
计算中心平均数
Centered Average
Background
In data analysis, sometimes to reduce the impact of extreme values on the average, a special kind of average is calculated.
Problem Description
Return the "centered" average of an array of integers, which is defined as the mean average of the values, except ignoring the largest and smallest values in the array. If there are multiple copies of the smallest value, ignore just one copy, and likewise for the largest value. Use integer division to produce the final average. You may assume that the array is length or more.
Input Format
The input consists of a single line string representing an array of integers. The string starts with [ and ends with ], with integers separated by spaces in between.
Output Format
The output is a single integer, representing the calculated centered average.
Sample
[1 2 3 4 100]
3
[1 1 5 5 10 8 7]
5
[-10 -4 -2 -4 -2 0]
-3
Sample Explanation
- Sample 1: For the array
[1 2 3 4 100], the smallest value is and the largest value is . After ignoring them, the remaining values are . Their sum is . There are remaining values. Using integer division, the centered average is . - Sample 2: For the array
[1 1 5 5 10 8 7], the smallest value is (one copy ignored) and the largest value is (one copy ignored). The remaining values are . Their sum is . There are remaining values. Using integer division, the centered average is . - Sample 3: For the array
[-10 -4 -2 -4 -2 0], the smallest value is and the largest value is . After ignoring them, the remaining values are . Their sum is . There are remaining values. Using integer division, the centered average is .
Constraints
Time limit: second, Memory limit: KiB for each test case.