求教!

P5726 【深基4.习9】打分

Whydy2010 @ 2022-07-05 15:14:46

一直WA,向大佬求教

#include <iostream>
#include <cstdio>
using namespace std;
int main() {
    int n;
    cin >> n;
    double a[n];
    double b=0;
    for (int i=0;i<n;i++){
        cin >> a[i];
    }
    double minn=a[0];
    double maxx=a[0];
    for (int i=1;i<n;i++){
        if (a[i]<minn){
            minn=a[i];
        }
        if (a[i]>maxx){
            maxx=a[i];
        }
    }

    for (int i=0;i<n;i++){
        b = b+a[i];
    }
    b=b-maxx-minn;
    b = b/(n-2); 
    printf("%.21f",b);
    return 0;
}

by Accelessar @ 2022-07-05 15:17:47

printf("%.21f",b);

l 打成 1


by ZHOUzihan415 @ 2022-07-05 15:18:44

 b = b/(n-2); 

这里改成

 b = (b*1.0)/(n-2); 

"/"默认是取整的


by Happy_Orca @ 2022-07-12 17:56:56

@ZHOUzihan415 只要运算的第一个是double类型,后面的都按照double类型运算


|