Volver a la lista de problemas
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); }