提交时间:2023-11-19 19:52:35
运行 ID: 31605
#include<iostream> #include<iomanip> #include<cmath> using namespace std; int main(){ int n,max_n=0,min_n=0; float max=0.0f,min=10000.0f; float sample[300]; float sum=0.0f,average=0.0f,error=0.0f,max_error=0.0f; cin >> n; for(int i=0;i<n;i++){ cin >> sample[i]; sum+=sample[i]; if(sample[i]>max){ max=sample[i]; max_n=i; } if(sample[i]<min){ min=sample[i]; min_n=i; } } average=(sum-max-min)/(n-2); for(int i=0;i<n;i++){ if( i!=max_n && i!=min_n ){ error=fabs(sample[i]-average); } if(error>max_error){ max_error=error; } } cout << fixed << setprecision(2) << average << " " << max_error << endl; return 0; }