#70. 计算中心平均数

    ID: 70 Type: Default 1000ms 256MiB Tried: 0 Accepted: 0 Difficulty: (None) Uploaded By: Tags>codingbatArray-2gesp4一维数组排序

计算中心平均数

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 33 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 11 and the largest value is 100100. After ignoring them, the remaining values are 2,3,42, 3, 4. Their sum is 2+3+4=92 + 3 + 4 = 9. There are 33 remaining values. Using integer division, the centered average is 9/3=39 / 3 = 3.
  • Sample 2: For the array [1 1 5 5 10 8 7], the smallest value is 11 (one copy ignored) and the largest value is 1010 (one copy ignored). The remaining values are 1,5,5,8,71, 5, 5, 8, 7. Their sum is 1+5+5+8+7=261 + 5 + 5 + 8 + 7 = 26. There are 55 remaining values. Using integer division, the centered average is 26/5=526 / 5 = 5.
  • Sample 3: For the array [-10 -4 -2 -4 -2 0], the smallest value is 10-10 and the largest value is 00. After ignoring them, the remaining values are 4,2,4,2-4, -2, -4, -2. Their sum is 4+(2)+(4)+(2)=12-4 + (-2) + (-4) + (-2) = -12. There are 44 remaining values. Using integer division, the centered average is 12/4=3-12 / 4 = -3.

Constraints

Time limit: 11 second, Memory limit: 10241024 KiB for each test case.