50分,求助真的找不到问题在哪

B2095 白细胞计数

zhouxiaolang @ 2023-05-16 20:02:03

#include<bits/stdc++.h>
using namespace std;
double a[10000];
int main()
{
    double mn=1000000000,mx=0;
    int n;
    cin>>n;
    double sum=0;
    for(int i=1;i<=n;i++)
    {
        cin>>a[i];
        if(a[i]<mn)
        mn=a[i];
        if(a[i]>mx)
        mx=a[i];
        sum+=a[i];
    }
    sum=(sum-mx-mn)/(n-2);
    double num=0;
    for(int i=1;i<=n;i++)
    {
        if(a[i]!=mx && a[i]!=mn)
        {
            if(num<fabs(a[i]-sum))
            num=fabs(a[i]-sum);
        }
    }
    printf("%.2f %.2f",sum,num);
    return 0;
}

by wangjiawen @ 2023-05-16 20:56:38

#include<bits/stdc++.h>
using namespace std;
int n;
float a[301],sum;
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-1;i++)
        sum+=a[i];
    sum/=(n-2);
    printf("%.2f %.2f",sum,max(sum-a[2],a[n-1]-sum));
    return 0;
}

虽然我也看不出错在哪里


by GoodCoder666 @ 2023-05-16 20:58:55

万一有多个相同的mx和mn呢?


by wangjiawen @ 2023-05-16 21:02:50

测了,可以过


by wangjiawen @ 2023-05-16 21:03:12

但是我也感觉这不对


by zhouxiaolang @ 2023-05-18 20:38:01

过了,栓q


|