下载测试点,对了,但是一个点都没过,求助!

P5726 【深基4.习9】打分

QXSSteven @ 2023-06-11 20:51:18

#include <iostream>
using namespace std;
int main(){
    int n,a[1001],ma = -1,mi = 11,s;
    cin >> n;
    for(int i = 1;i <= n;i++){
        cin >> a[i];
        s += a[i];
        if(a[i] > ma) ma = a[i];
        if(a[i] < mi) mi = a[i];
    }
    printf("%.2lf",(s - ma - mi) / (n - 2.0));
    return 0;
}

by ninji @ 2023-06-11 20:59:06

#include<stdio.h>
int main() 
{
    int i,j,n;
    double lev,tem,sum=0;
    double a[10000];
    scanf("%d",&n);
    for(i=0;i<n;i++)
    {
        scanf("%lf",&a[i]);
    }
    for(i=0;i<n;i++)
    {
        for(j=0;j<n-i-1;j++)
        {
            if(a[j]>a[j+1])
            {
                tem=a[j];
                a[j]=a[j+1];
                a[j+1]=tem;
            }
        }
    }
    for(i=0;i<n;i++)
    {
       sum+=a[i];
       lev=(sum-a[0]-a[i])/(n-2);
    }
    printf("%.2lf",lev);
    return 0;
}

@qxsqxs


by L_zaa_L @ 2023-06-11 21:04:17

@qxsqxs 定义变量用float就过了


by QXSSteven @ 2023-06-11 21:05:24

@ninji Thanks


by QXSSteven @ 2023-06-11 21:06:47

@zaa 还真是


by sxjsxj @ 2023-06-11 21:25:43

建议你输出不要用n-2.0,用(s-ma-mi)*1.0


by 1000YMH @ 2023-07-26 09:31:55


#include<bits/stdc++.h>
using namespace std;
int main(){
    int a,i,s[1001],d=11,f=0;
    double g=0;
    cin>>a;
    for(i=0;i<a;i++){
        cin>>s[i];
        if(s[i]<d)d=s[i];
        if(s[i]>f)f=s[i];
    }
    for(i=0;i<a;i++)g+=s[i];
    g=(g-d-f)/(a-2);
    cout<<fixed<<setprecision(2)<<g;
}

|