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

Greedy Gift Givers

119.c

/* Greedy Gift Givers */
#include <stdio.h>
#include <stdlib.h>

char names[10][13];
int amounts[10];

int
main(void)
{
	int i,j,k;
	int people;
	int ini=-1;
	char tmp[13];

	while(1) {
		ini++;
		if (scanf("%d", &people) != 1) {
			break;
		}
		for(i=0; i<people; i++) {
			scanf("%s", names[i]);
			amounts[i]=0;
		}
		for(i=0; i<people; i++) {
			int amount, num;
			int tio;

			scanf("%s", tmp);
			for(j=0; j<people; j++) {
				if (!strcmp(tmp, names[j])) {
					tio = j;
					break;
				}
			}
			scanf("%d %d", &amount, &num);
			if (num) {
				amount /= num;
				amounts[tio] -= amount*num;
				for(j=0; j<num; j++) {
					scanf("%s", tmp);
					for(k=0; k<people; k++) {
						if (!strcmp(tmp, names[k])) {
							amounts[k] += amount;
							break;
						}
					}
				}
			}
		}
		if (ini) {
			printf("\n");
		}
		for(i=0; i<people; i++) {
			printf("%s %d\n", names[i], amounts[i]);
		}
	}
	exit(0);
}