Tips:先求出平均数再分别计算各数与平均数的差相加,注意两个测试结果之间要空一行
1 #include<iostream> 2 using namespace std; 3 int main() 4 { 5 int T,count=0; 6 while(cin>>T) 7 { 8 if(T==0) 9 { 10 return 0; 11 } 12 count ++; 13 int b[T],sum=0,totalsum=0,avg=0; 14 for(int i=0;i<T;i++) 15 { 16 cin>>b[i]; 17 sum += b[i]; 18 } 19 avg = sum/T; 20 for(int i=0;i<T;i++) 21 { 22 if(b[i]>avg) 23 { 24 totalsum += b[i]-avg; 25 } 26 } 27 cout<<"Set #"<<count<<endl; 28 cout<<"The minimum number of moves is "<<totalsum<<"."<<endl; 29 cout<<endl; 30 31 } 32 return 0; 33 }