Photolog

Through the Looking-Glass
2010-10-12: Through the Looking-Glass
My radio speaks is binary!
2010-10-10: My radio speaks is binary!
Gigaminx: (present for my birthday)
2010-09-16: Gigaminx: (present for my birthday)
Trini on bike
2010-09-05: Trini on bike
Valporquero
2010-08-28: Valporquero
My new bike!
2010-08-22: My new bike!
Mario and Ana's wedding
2010-08-13: Mario and Ana's wedding
Canyoning in Guara
2010-08-07: Canyoning in Guara
Trini and Mari in Marbella
2010-08-05: Trini and Mari in Marbella
Trini and Chelo in Tabarca
2010-08-03: Trini and Chelo in Tabarca
Valid XHTML 1.1
Log in
Back to list of problems

Box of Bricks

591.c

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int num;
int bricks[50];

void calculate(int set)
{
	int total=0;
	int i;
	int moves=0;

	for(i=0; i<num; i++) {
		total+=bricks[i];
	}
	for(i=0; i<num; i++) {
		if (bricks[i]>(total/num)) {
			moves+=bricks[i]-(total/num);
		}
	}
	printf("Set #%d\n", set);
	printf("The minimum number of moves is %d.\n\n", moves);
}

int main(void)
{
	int i;
	int set;

	for(set=1;;set++) {
		if ((fscanf(stdin, " %d", &num)!=1) || (num==0)) {
			exit(0);
		}
		for(i=0; i<num; i++) {
			if (fscanf(stdin, " %d", &bricks[i])!=1) {
				exit(1);
			}
		}
		calculate(set);
	}
	exit(0);
}