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 ;
}