啊啊啊ε=ε=ε=(#>д<)ノ60分

B2095 白细胞计数

wwbtty @ 2023-08-18 14:42:27

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

by qinshi0308 @ 2023-08-18 14:48:02

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

by qinshi0308 @ 2023-08-18 14:50:42

@wwbtty


by wwbtty @ 2023-08-18 14:55:10

thanks!


|