蒟蒻求助

P5726 【深基4.习9】打分

popbattle @ 2021-06-25 14:29:34

不知道哪里好像写错了AC不了求大佬帮忙看看QAQ

#include<bits/stdc++.h>
using namespace std;
int main (){
    int a[1000], n, max=-1, min=11, all=0;
    double total;
    cin>>n;
    for(int i=1;i<=n;i++){
        cin>>a[i];
        if(a[i]>max){max=a[i];}
        if(a[i]<min){min=a[i];}
        all+=a[i];
    }
    total=double((all-min-max)/(n-2));
    printf("%.2lf",total);
    return 0;
}

by _Error_ @ 2021-06-25 15:23:45

double套错了,丢精度

#include<bits/stdc++.h>
using namespace std;
int main (){
    int a[100005], n, max=-1, min=11, all=0;
    double total;
    cin>>n;
    for(int i=1;i<=n;i++){
        cin>>a[i];
        if(a[i]>max){max=a[i];}
        if(a[i]<min){min=a[i];}
        all+=a[i];
    }
    total=((double)(all-min-max)/(n-2));
    printf("%.2lf",total);
    return 0;
}

by popbattle @ 2021-06-25 16:05:16

@Error AC了感谢感谢


|