为什么全红阿 测试都对啊

P5726 【深基4.习9】打分

lyx8094 @ 2024-06-06 10:54:57

#include<bits/stdc++.h>
using namespace std;
int main(){
    int n;cin>>n;
    int a[1001],i;
    for(i=1;i<=n;i++){
        cin>>a[i];
    }
    sort(a,a+n+1);

double sum=0;
    for(i=2;i<n;i++){
        sum=sum+a[i];
    }printf("%.2f",sum/(n-2));
}

by ltl0825 @ 2024-06-06 10:59:07

@lyx8094 应该是sort(a+1,a+1+n);


by SCP035 @ 2024-06-06 12:25:14


#include<bits/stdc++.h>

using namespace std;

int main(){

    int n,a[10001],s=1,j=1000,sum=0;

    cin>>n;

    for(int i=0; i<n; i++){

        cin>>a[i];

        sum=sum+a[i];
    }
for(int i=0; i<n; i++){

  s = max(s,a[i]);

  j = min(j,a[i]);
}
    sum = sum-s-j;

    cout<<fixed<<setprecision(2)<<sum*1.0/(n-2);

    return 0;
}

by SCP035 @ 2024-06-06 12:25:54

@lyx8094 我用的循环


by coderzhx @ 2024-06-06 21:32:57

#include <iostream>
using namespace std;

long p = -66666;
long q = 88888;
double a[50000];
double n;

double sum;

int main() {
    cin >> n;
    for (int i = 1; i <= n; i++) {
        cin >> a[i];
        sum += a[i];

        if (a[i] > p) {
            p = a[i];
        }
        if (a[i] < q) {
            q = a[i];
        }

    }
    printf("%.2lf", (sum - (p + q)) / (n - 2) * 1.0);

    return 0;
}

@ltl0825


by HuangSiHan3116 @ 2024-07-19 08:51:42

@lyx8094 这样就行。本人很垃圾。不喜勿喷。

#include<bits/stdc++.h>
using namespace std;
int main(){
    double n,m==11,M==-1,sum;
    cin>>n;
    for(int i=1;i<=n;++i){
        int x;
        cin>>x;
        sum+=x;
        if(x>M){
            M=x;
        }
        if(x<m){
            m=x;
        }
    }
    printf("%.2lf",(sum-M-m)/(n-2.0));
    return 0;
}

|