shantz123 @ 2024-12-22 19:19:30
求教:
#include<bits/stdc++.h>
using namespace std;
int main(){
double a,l2[100000],p,s=0,m=-1e18,n=1e18;
cin>>a;
for(int i=1;i<=a;i++){
cin>>l2[i];
if(l2[i]>m){
m=l2[i];
}
if(l2[i]<n){
n=l2[i];
}
s+=l2[i];
}
s=s-m-n;
s=s/(a-2);
m=-1e18;
for(int i=1;i<=a;i++){
if(l2[i]<s){
p=s-l2[i];
}
else{
p=l2[i]-s;
}
if(s>m){
m=p;
}
}
cout<<fixed<<setprecision(2)<<s<<" "<<m;
}
by Diary_Of_Young @ 2024-12-25 17:03:19
#include<bits/stdc++.h>
using namespace std;
double a[101001] , sum , cnt;
int n;
int main()
{
cin >> n;
for(int i = 1; i <= n; i ++) cin >> a[i] ;
sort(a + 1 , a + n + 1);
for(int i = 2 ; i < n ; i ++) sum += a[i];
sum = 1.0 * sum / (n - 2);
for(int i = 2 ; i < n ; i ++) cnt = max(cnt , fabs(sum - 1.0 * a[i]));
printf("%.2lf %.2lf " , sum , cnt);
return 0;
}