help me!!!

B2095 白细胞计数

vector_STL_ @ 2024-08-28 16:54:14

#include<bits/stdc++.h>
using namespace std;

int main() {
    int n,h,maxn=0;
    cin>>n;
    vector<double>s(n);
    for(int i=1;i<=n;i++){
        double a;
        cin>>a;
        s.push_back(a);
        h=0;
        h=h+a;
    }

    h=h-*s.begin()-*s.end();
    *s.begin()=0;
    *s.end()=0;
    printf("%.2lf\40 ",h*1.0/s.size()-2);
    for(auto c:s){
        if(c>maxn){
            maxn=c;
        }
    }
    printf("%.2lf",maxn-h/s.size()*1.0);

    return 0;
}

by pff20121005 @ 2024-11-23 15:17:27

#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;
}

|