ACM PKU 1477 Box of Bricks 簡單題
http://acm.pku.edu.cn/JudgeOnline/problem?id=1477
Source
Problem Id:1477 User Id:lnmm
Memory:116K Time:0MS
Language:C++ Result:Accepted
1
#include"iostream.h"
2
int a[51];
3
void main()
4

{
5
int T;
6
int i;
7
int sum,avg;
8
int c=0;
9
while((cin>>T)&&T!=0)
10
{
11
sum=0;
12
avg=0;
13
for(i=1;i<=T;i++)
14
{cin>>a[i];
15
sum+=a[i];
16
}
17
avg=sum/T;
18
sum=0;
19
for(i=1;i<=T;i++)
20
{
21
if(a[i]>avg)sum=sum+a[i]-avg;
22
}
23
cout<<"Set #"<<++c<<endl;
24
cout<<"The minimum number of moves is "<<sum<<"."<<endl;
25
cout<<endl;
26
}
27
28
29
30
}
31
#include"iostream.h"2
int a[51];3
void main()4


{5
int T;6
int i;7
int sum,avg;8
int c=0;9
while((cin>>T)&&T!=0)10

{11
sum=0;12
avg=0;13
for(i=1;i<=T;i++)14

{cin>>a[i];15
sum+=a[i];16
}17
avg=sum/T;18
sum=0;19
for(i=1;i<=T;i++)20

{21
if(a[i]>avg)sum=sum+a[i]-avg;22
}23
cout<<"Set #"<<++c<<endl;24
cout<<"The minimum number of moves is "<<sum<<"."<<endl;25
cout<<endl;26
}27

28

29

30
}31


