UVa 119 - Greedy Gift Givers

Summary
A typical Simulation problem. Follow the instruction carefully.

Explanation
N can be at most 10, so the naive array implementation will do.
 * 1) include
 * 2) include
 * 3) include 
 * 4) include 
 * 5) include 
 * 6) include 

using namespace std;

int stt; char tennguoi[130],ten[11][15]; int songuoi,tiencho,songuoinhan; int tien[11][2]; char nguoicho[15]; char nguoinhan[15];

int timten(char a[],char b[11][15]) {	int i,j; for(i=0;i<songuoi;i++) for(j=0;j<15;j++) {			if(b[i][j]==' ' && a[j]=='\0') return i;			if(a[j]!=b[i][j]) break; } }

void solve {	int z,du; du=tiencho%songuoinhan; z=timten(nguoicho,ten); tien[z][0]=tien[z][0]-tiencho+du; }

void solve2 {	int x;	x=timten(nguoinhan,ten); tien[x][0]=tien[x][0]+tiencho/songuoinhan; }

void output {	int i,j; if(stt!=0) printf("\n"); for(i=0;i0) {		khoitri(tien); if(songuoi==0) break; else {				reset(tennguoi); gets(tennguoi); k=0; for(i=0;i0) {					solve; for(j=0;j<songuoinhan;j++) {						reset(nguoinhan); scanf("%s",&nguoinhan); solve2; }					}			}			output; stt++; }	}	return 0; }

Gotcha's
Names should be printed in the order they appeared. Put one more line at the end will give your feedback as wrong answer (not presentation error as usual). One trick to avoid this is to print a newline before output the answers for every group except the first group. For example, use a counter,

Input
5 dave laura owen vick amr dave 200 3 laura owen vick owen 500 1 dave amr 150 2 vick owen laura 0 2 amr vick vick 0 0 3 liz steve dave liz 30 1 steve steve 55 2 liz dave dave 0 2 steve liz

Output
dave 302 laura 66 owen -359 vick 141 amr -150

liz -3 steve -24 dave 27

Solution
C++: http://acm-solution.blogspot.com/2010/11/acm-uva-119-greedy-gift-givers.html