2018年1月13日 星期六

UVA Q591 - Box of Bricks

#include<iostream>
#include<math.h>
#include<cstring>
#include<iomanip>
using namespace std;
int main(){
    int a,b[50],c,d,e=0;
    while(cin>>a){
        e++;
        if(a==0){
            break;
        }
        c=0;
        d=0;
        for(int x=0;x<a;x++){
            cin>>b[x];
            c=c+b[x];
        }
        c=c/a;
        for(int x=0;x<a;x++){
            if(b[x]>c){
                d=d+b[x]-c;
            }
        }
        cout<<"Set #"<<e<<endl<<"The minimum number of moves is "<<d<<"."<<endl<<endl;
    }
system ("pause");
return 0;
}

沒有留言:

張貼留言