50分奆悲,求助

B2095 白细胞计数

James_Qiao @ 2024-11-16 09:51:56

#include<bits/stdc++.h>
#include<cmath>
using namespace std;
int main(){
    int n;
    cin>>n;
    float l[n+5];
    float num,ans=0;
    for(int i = 0;i<n;i++)
    {
        cin>>num;
        l[i]=num;
        ans+=num;
    }
    float maxnum=0;
    float minum=6.805646932770577*pow(10,38);
    for(int i = 0;i<n;i++)
    {
        maxnum=max(l[i],maxnum);
        minum=min(l[i],minum);
    }
    ans-=(maxnum+minum);
    cout<<fixed<<setprecision(2)<<ans/(n-2)<<" ";
    float maxd=0;
    for(int i=0;i<n;i++){
        if(l[i]!=maxnum&&l[i]!=minum){
            maxd=max(maxd,abs(l[i]-(ans/(n-2))));
        }
    }
    cout<<fixed<<setprecision(2)<<maxd<<endl;;
    return 0;
}

by pff20121005 @ 2024-11-23 15:19:07

#include<iostream>
#include<cmath>
using namespace std;
double a[100000];
int main(){
    int n,maxi = 1,mini = 1;
    double y = 0,maxn = -1,sum = 0;
    cin>>n;
    for(int i = 1;i <= n;i++){
        cin>>a[i];
        sum += a[i];
        if(a[i] > a[maxi])maxi = i;
        if(a[i] < a[mini])mini = i; 
    }
    y = (sum - a[maxi] - a[mini]) / (n - 2.0);
    for(int i = 1;i <= n;i++){
        if(i != maxi && i != mini){
            if(fabs(a[i] - y) > maxn)maxn = fabs(a[i] - y);
        }
    }
    printf("%.2lf %.2lf",y,maxn);
    return 0;
}

|