基础题。
#include <iostream>
using namespace std;
const int MAXN = 55;
int high[MAXN]; //每组木块的高度
int main()
{
int Case = 1; //测试用例数
int n;
while (cin >> n)
{
if (n == 0)
break;
int sum = 0; //木块的总数
for (int i = 0; i < n; i++)
{
cin >> high[i];
sum += high[i];
}
int average = sum / n; //每组木块的平均高度
int count = 0; //移动次数
for (int i = 0; i < n; i++)
{
if (high[i] > average)
count += (high[i] - average);
}
cout << "Set #" << Case++ << endl;
cout << "The minimum number of moves is " << count << "." << endl;
cout << endl;
}
return 0;
}
继续加油。