成绩分析

成绩分析

https://ac.nowcoder.com/acm/contest/6607/C

图片说明
思路:这道题是一个很简单的模拟题,根据题意求出班级成绩的中位数和平均数后相减再取绝对值就就可以了。
参考代码如下:

#include<iostream>
using namespace std;
int a[105];
int main()
{
    ios::sync_with_stdio(false);
    int n,res=0,ans=0;
    cin>>n;
    for(int i=1;i<=n;i++)
    {
        cin>>a[i];
        ans+=a[i];
    }
    ans/=n;
     if(n%2==0)
    {
        res=(a[n/2]+a[n/2+1])/2;
    }
    else
    {
        res=a[n/2+1];
    }
    if(ans>res)
    cout<<ans-res<<endl;
    else
    {
        cout<<res-ans<<endl;
    }
    return 0;
}
全部评论

相关推荐

07-25 11:12
重庆大学 C++
既然这么缺人,为什么挂我呢
希望被offer砸中...:其实不缺人
点赞 评论 收藏
分享
苍蓝星上艾露:这简历。。。可以试试我写的开源简历优化工具https://github.com/weicanie/prisma-ai
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务