CoderMC @ 2025-01-06 19:11:27
#include<bits/stdc++.h>
using namespace std;
int n;
double a[320];
//double sum,maxd
int main(){
cin>>n;
for(int i=1;i<=n;i++){
cin>>a[i];
}
sort(a+1,a+n+1);
double sum,maxd;
for(int i=2;i<=n-1;i++){
sum=sum+a[i];
}
sum=sum/(n-2);
maxd=max(fabs(a[2]-sum),fabs(a[n-2]-sum));
cout<<fixed<<setprecision(2)<<sum<<" "<<maxd;
return 0;
}
by Greedy_ @ 2025-01-06 20:19:37
你这样写最大的不应该是a[n]吗,去掉那么第二大的是a[n-1],你写的是a[n-2].
by CoderMC @ 2025-01-07 11:33:52
@Greedy_thanks!