感觉没错但都不对,蒟蒻求助

P5726 【深基4.习9】打分

qyb0713 @ 2024-03-03 10:59:05

#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,x,sum,minn=10,maxn=0;
    cin>>n;
    for(int i=1;i<=n;i++)
    {
        cin>>x;
        sum+=x;
        if(x<minn) minn=x;
        if(x>maxn) maxn=x;
    }
    printf("%.2f",(sum-maxn-minn)*1.0/(n-2));
    return 0;
}

by quxiangyu @ 2024-03-03 11:05:28

@qyb0713 @qyb0713 求关注

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

by hema5177 @ 2024-03-03 11:06:45

@qyb0713 应该是你sum没赋值为0


by wangzhiqin @ 2024-03-03 11:08:09

@quxiangyu 你就复制了一遍题解....


by wangzhiqin @ 2024-03-03 11:08:29

@qyb0713 sum初始化0


by qyb0713 @ 2024-03-03 11:16:21

@hema5177 谢谢


by hema5177 @ 2024-03-03 11:36:36

@qyb0713 不用谢qwq


by Brian1 @ 2024-03-03 12:14:51

一定要用列表么?


by anyiming @ 2024-05-22 23:16:30

@Brian1 不一定要用列表啊


|