#include <iostream>
using namespace std;
int main()
{
int n, h[n];
while(cin>>n)
{
if(n==0) break;
int set=0;
int ans=0;
for(int i=0 ; i<n ; i++) {
cin>>h[i];
ans=( ans+h[i] ) / n;
}
int count=0;
for(int i=0 ; i<n ; i++) {
if(h[i]>n) count+=h[i]-ans;
}
set+=1;
cout<<"Set #"<< set <<"\nThe minimum number of moves is "<<count<<"."<<endl;
}
return 0;
}
#include
using namespace std;
int main()
{
int n, h[n];
while(cin>>n)
{
if(n==0) break;
int set=0;
int ans=0;
for(int i=0 ; i
cin>>h[i];
ans=( ans+h[i] ) / n;
}
int count=0;
for(int i=0 ; i
if(h[i]>n) count+=h[i]-ans;
}
set+=1;
cout<<"Set #"<< set <<"\nThe minimum number of moves is "<<count<<"."<<endl;
}
return 0;
}
1. 宣告h陣列時n還沒初始化
2. 平均高度算法錯誤
3. set宣告放到迴圈外
4. if(h[i]>n)的n改成ans