C++ 60分不知哪里错了 求助大佬们!

P5726 【深基4.习9】打分

JJay118 @ 2020-09-15 20:04:49


#include<algorithm>
#include<iomanip>
using namespace std;

int main()
{
    int a = 0;
    cin >> a;

    double arr[110];
    double sum = 0;
    double avr = 0;

    for(int i = 0; i < a; i++)
    {
        cin >> arr[i];
    }

    sort(arr,arr + a);

    if(a > 2)
    {
        for(int i = 1; i < a-1;i++)
        {
            sum+= arr[i];
        }

        avr = sum / (a - 2);
    }
    else if(a == 2)
    {
    avr = (arr[0]+ arr[1]) / 2;
    }
    else if( a < 2)
    {
        avr = arr[0];
    }
    cout << fixed << setprecision(2) << avr;
    return 0;
}```

by zky06 @ 2020-09-15 20:06:21

数组设大点啊。。


by JJA_ @ 2020-09-15 20:15:49

double arr[110];——>long double arr[1005]


by JJA_ @ 2020-09-15 20:16:09

现在都不看数据范围的吗...


by John_yangliwu @ 2020-09-15 20:19:07

楼上、楼上上、楼上上上正解


by JJA_ @ 2020-09-15 20:31:27

又是一个发完帖就跑的萌新


by JJay118 @ 2020-09-16 14:48:01

谢谢大佬们!!


by JJay118 @ 2020-09-16 14:48:29

@蒟蒻JJA 不好意思 谢谢!


|