UVA 591 Solution
Solve in C:
#include<stdio.h>
int main()
{
int n,i,sum=0,mov=0,count=1,avg,ar[100];
while(scanf("%d",&n)!=EOF)
{
if(n==0)
break;
{
sum=0;
mov=0;
for(i=0; i<n; i++)
{
scanf("%d",&ar[i]);
}
for(i=0; i<n; i++)
{
sum=sum+ar[i];
}
avg=sum/n;
for(i=0; i<n; i++)
if(ar[i]>avg)
mov=mov+(ar[i]-avg);
}
printf("Set #%d\nThe minimum number of moves is %d.\n",count,mov);
count++;
printf("\n");
}
return 0;
}
#include<stdio.h>
int main()
{
int n,i,sum=0,mov=0,count=1,avg,ar[100];
while(scanf("%d",&n)!=EOF)
{
if(n==0)
break;
{
sum=0;
mov=0;
for(i=0; i<n; i++)
{
scanf("%d",&ar[i]);
}
for(i=0; i<n; i++)
{
sum=sum+ar[i];
}
avg=sum/n;
for(i=0; i<n; i++)
if(ar[i]>avg)
mov=mov+(ar[i]-avg);
}
printf("Set #%d\nThe minimum number of moves is %d.\n",count,mov);
count++;
printf("\n");
}
return 0;
}
No comments