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

The Dole Queue

133.c

#include <stdio.h>

int people[21];

int
main(void)
{
	int N,k,m;
	int i;
	while(1) {
		int pos1,pos2;
		int a;
		int inicio=1;

		if (scanf(" %d %d %d", &N, &k, &m)!=3) {
			exit(0);
		}
		if (N==0) {
			exit(0);
		}
		pos1=1;
		pos2=N;
		for(i=1; i<=N; i++) {
			people[i]=1;
		}
		while(1) {
			int done=1;
			for(i=1; i<=N; i++) {
				if (people[i]) {
					done=0;
					break;
				}
			}
			if (done) {
				break;
			}
			a=0;
			while(1) {
				if (people[pos1]) {
					a++;
				}
				if (a==k) {
					break;
				}
				pos1++;
				if (pos1>N) {
					pos1=1;
				}
			}
			a=0;
			while(1) {
				if (people[pos2]) {
					a++;
				}
				if (a==m) {
					break;
				}
				pos2--;
				if (pos2<1) {
					pos2=N;
				}
			}
			people[pos1]=people[pos2]=0;
			if (!inicio) {
				printf(",");
			}
			inicio=0;
			if (pos1==pos2) {
				printf("%3d", pos1);
			} else {
				printf("%3d%3d", pos1, pos2);
			}
		}
		printf("\n");
	}
	exit(0);
}