提交时间:2024-10-27 11:57:49

运行 ID: 54352

#include<bits/stdc++.h> using namespace std; int main(){ int n, k, l, t = 0; cin >> n; double a[300], sum = 0; for(int i = 0; i < n; i++){ cin >> a[i]; } double largest = -100, smallest = 10000, larg = -100; for(int i = 0; i < n; i++){ if(a[i] > largest){ largest = a[i]; k = i; } if(a[i] < smallest){ smallest = a[i]; l = i; } } a[k] = 0; a[l] = 0; for(int i = 0; i < n; i++){ if(a[i] != 0){ sum += a[i]; } } double ave = sum/(n - 2); double b[300]; for(int i = 0; i < n; i++){ if(a[i] != 0){ b[t] = abs(a[i]-ave); t++; } } for(int i = 0; i < n - 2; i++){ if(b[i] > larg){ larg = b[i]; } } cout << fixed << setprecision(2) << ave <<" " << larg <<endl; return 0; }