【杭电100题】2088 Box of Bricks

题目:http://acm.hdu.edu.cn/showproblem.php?pid=2088

#include <iostream>

using namespace std;

int main()
{
    int n;
    int h[51];
    int flag=0;
    while(cin>>n && n)
    {
        int total=0;
        for(int i=1; i<=n; i++)
        {
            cin>>h[i];
            total+=h[i];
        }
        int aver=total/n;
        int num=0;
        for(int i=1; i<=n; i++)
        {
            if(h[i]>aver)
                num+=(h[i]-aver);
        }
        if(flag!=0)
            cout<<endl;
        flag++;
        cout<<num<<endl;
    }
    return 0;
}

猜你喜欢

转载自blog.csdn.net/qq_41727666/article/details/88429369
Box
今日推荐