求助 答案正确 但WA

P5726 【深基4.习9】打分

wohainengxueyidian @ 2024-04-10 22:13:55

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

int main(){
    int n,a[1001],sum;
    double rank;
    cin>>n;
    for(int i=0;i<n;i++){
        //TODO
        cin>>a[i];
        sum+=a[i];
    }
    rank=1.0*(sum-*max_element(a,a+n)-*min_element(a,a+n))/(n-2);
    cout<<fixed<<setprecision(2)<<rank;
    return 0;
}

by Dream_Creator @ 2024-04-10 22:16:21

@wohainengxueyidian


#include<bits/stdc++.h>
using namespace std;
int n,a[1001],sum;

int main(){
    double rank;
    cin>>n;
    for(int i=0;i<n;i++){
        //TODO
        cin>>a[i];
        sum+=a[i];
    }
    rank=1.0*(sum-*max_element(a,a+n)-*min_element(a,a+n))/(n-2);
    cout<<fixed<<setprecision(2)<<rank;
    return 0;
}

by Dream_Creator @ 2024-04-10 22:17:06

@wohainengxueyidian sum 没初始化为 0(求关注)


by wohainengxueyidian @ 2024-04-12 10:32:57

@Dream_Creator 感谢大佬,我是真没脑子


by LiXiang190208 @ 2024-05-12 12:05:45

#include<bits/stdc++.h>
using namespace std;
int main(){
    int n,a[1000],s=1,j=1000,sum=0;
    cin>>n;
    for(int i=0;i++;i<n){
        cin>>a[i];
        sum+=a[i];
    }
    for(int i=0;i++;i<n){
        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;
}

大佬们,为什么只能输入n

新手哟!!


|