50分求助 急!!!

B2095 白细胞计数

czh1 @ 2023-10-15 17:00:07

#include<stdio.h>
double a[300],sum=0.0,min=999999999.0,max=0.0,maxi=0.0,mini=999999999.0;
int main(){
    int n;
    scanf("%d",&n);
    for(int i=0;i<n;i++){
        scanf("%lf",&a[i]);
        if(max<a[i]){
            max=a[i];
        }
        if(min>a[i]){
            min=a[i];
        }
        sum+=a[i];
    }
    double p=(sum-max-min)/(n-2);
    for(int i=0;i<n;i++){
        if(maxi<a[i]&&a[i]!=max){
            maxi=a[i];
        }
        if(mini>a[i]&&a[i]!=min){
            mini=a[i];
        }
    }
    printf("%.2lf ",p);
    if((maxi-p)>(p-mini)){
        printf("%.2lf",maxi-p);
    }else{
        printf("%.2lf",p-mini);
    }
    return 0;
} 

by Huangziyu2022 @ 2023-10-15 17:26:43

有点麻烦


by Huangziyu2022 @ 2023-10-15 17:35:48

为什么是sun+=a[i]???


by Huangziyu2022 @ 2023-10-15 18:08:51

#include<bits/stdc++.h>
using namespace std;
int main(){
    double a[301],sum=0,maxn,b;
    int n,j,i;
    cin>>n;
    for(i=1;i<=n;i++){
        cin>>a[i];
        sum+=a[i];
    }
    sort(a+1,a+n+1);
    sum=sum-a[1]-a[n];
    double d=n-2.0;
    double ping=sum/d;
    double ans=abs(sum*d-ping*d);
       for(int i=2; i<=n-1; i++)
        if(fabs(ping-a[i]) > maxn)
            maxn=fabs(ping-a[i]);
    printf("%.2f %.2f",ping,maxn);

    return 0;
}
cin>>n;
for(i=1;i<=n;i++){
    cin>>a[i];
    sum+=a[i];
}
sort(a+1,a+n+1);
sum=sum-a[1]-a[n];
double d=n-2.0;
double ping=sum/d;
double ans=abs(sum*d-ping*d);
   for(int i=2; i<=n-1; i++)
    if(fabs(ping-a[i]) > maxn)
        maxn=fabs(ping-a[i]);
printf("%.2f %.2f",ping,maxn);

return 0;

}


by czh1 @ 2023-11-05 14:52:07

谢谢大佬


|