这道题的大意是讲:给出一系列的不同高度箱子,要把各各箱子的高度变成相同的高度,问你要移动多少次箱子。很简单,不过得注意输出格式。
#include <iostream>
//#include<stdio.h>
#include<stdlib.h>
#include<math.h>
using namespace std;
int main()
{
int n,a[1000],sum,i,temp,count,k = 1;
while((cin >> n) && n != 0)
{
sum = 0;
count = 0;
for(i = 0 ; i < n; i++ )
{
cin >> a[i];
sum += a[i];
}
temp = sum/n;
for(i = 0; i < n; i++)
{
count += fabs(a[i] - temp);
}
cout << "Set " << "#" << k << endl;
k++;
cout << "The minimum number of moves is "<< count/2 <<"." << endl;
cout << endl;
}
return 0;
}