20分,求助!!!!!

P5726 【深基4.习9】打分

qaz20130205 @ 2024-09-07 13:05:13


#include<iostream>
using namespace std;
int main()
{
    int a,n,b,c;
    float sum=0;
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>a;
        b=max(b,a);
        c=min(c,a);
        sum=sum+a;
    }
    sum=(sum-b-c)/(n-2);
    printf("%.2f",sum);
    return 0;
}

by Deric456 @ 2024-09-07 13:11:31

b、c没有初始化


by Deric456 @ 2024-09-07 13:13:46

b=-999999
c=999999
@qaz20130205


by Deric456 @ 2024-09-07 13:14:37

改的AC代码


#include<bits/stdc++.h>
using namespace std;
int main()
{
    int a,n,b=0,c=999999;
    double sum=0;
    cin>>n;
    for(int i=1;i<=n;i++){
        cin>>a;
        b=max(b,a);
        c=min(c,a);
        sum=sum+a;
    }
    sum=(sum-b-c)/(n-2);
    printf("%.2f",sum);
    return 0;
}

by Deric456 @ 2024-09-07 13:14:57

求关


by qaz20130205 @ 2024-09-07 13:34:49

已AC,谢谢


by keyifan520 @ 2024-09-07 13:37:54

@qaz20130205

int n;
cin >> n;
float ans = 0, maxNum = -1, minNum = 100;
int p = n;
while (n--) {
    float x;
    cin >> x;
    ans += x;

    maxNum = max(x, maxNum), minNum = min(x, minNum);
}
printf("%.2f", (ans - maxNum - minNum) / (p - 2.0));
return 0;

}


by wang_qian_xi1 @ 2024-09-10 20:32:44

最好不要用float,要用double

虽然这和本题没有联系


|