杭电oj1326 Box of Bricks

时间:2024-08-09 13:06:08

Tips:先求出平均数再分别计算各数与平均数的差相加,注意两个测试结果之间要空一行

 #include<iostream>
using namespace std;
int main()
{
int T,count=;
while(cin>>T)
{
if(T==)
{
return ;
}
count ++;
int b[T],sum=,totalsum=,avg=;
for(int i=;i<T;i++)
{
cin>>b[i];
sum += b[i];
}
avg = sum/T;
for(int i=;i<T;i++)
{
if(b[i]>avg)
{
totalsum += b[i]-avg;
}
}
cout<<"Set #"<<count<<endl;
cout<<"The minimum number of moves is "<<totalsum<<"."<<endl;
cout<<endl; }
return ;
}