#include <bits/stdc++.h> using namespace std; //从资源开销上看,本AC代码质量很差 //因为使用冒泡从小到大排列,时间开销大,最好是使用两个哨兵,遍历数组后标记最小最大值的下标 int main() { int n; double a[300]; cin >> n; double temp; for (int i = 0; i < n; i++) { cin >> a[i]; } //冒泡,首尾是最小最大值 for (int i = 0; i < n; i++) { for (int j = i; j < n; j++) { if (a[i] > a[j]) { temp = a[i]; a[i] = a[j]; a[j] = temp; } } }
//去除最大最小值后,计算平均值
double sum = 0;
double average;
for (int i = 1; i < n - 1; i++) {
sum += a[i];
}
average = sum / (n - 2);
//计算每个值与平均值 差的绝对值,并输出最大值
double max_a;
for (int i = 1; i < n - 1; i++) {
max_a = max(max_a, fabs(a[i] - average));
}
printf("%.2f %.2f", average, max_a);
return 0;
}