20分求助,谢谢谢谢

P5726 【深基4.习9】打分

Ryoo @ 2024-01-10 18:13:27

#include <bits/stdc++.h>
using namespace std;
int main() {
    int i,j,n,x = 0,sum = 0;
    scanf("%d", &n);
    int a[n],b[11];
    for(i = 1; i <= 10; i++)    b[i] = 0;
    for(i = 0; i < n; i++) scanf("%d", &a[i]);
    for(i = 0; i < n; i++) {
        for(j = 1; j <= 10; j++) {
            if(a[i] == j)   b[j]++;
        }
    }

    for(i = 1; i <= 10; i++) {
        while(b[i] > 0) {
            a[x] = i;
            x++;b[i]--;
        }
    }

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

by LHX_18460366315 @ 2024-01-12 20:39:54

@Chao08 用我这个:

#include<bits/stdc++.h>
using namespace std;
int main(){
    int n,num[1005];
    float a = 0;
    cin >> n;
    for (int i = 1;i <= n;i++){
        cin >> num[i];
    }
    sort(num + 1,num + (n + 1));
    for (int i = 2;i < n;i++){
        a += num[i];
    }
    printf("%.2f",a / (n - 2));
    return 0;
}

|