1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65
| #include <stdio.h> #include <string.h>
int book[100]; int main(){ int n,k,m; int kcount,mcount; int ki,mi; int kout,mout; int first; int ncount; while(scanf("%d%d%d",&n,&k,&m)==3&&n&&k&&m){ memset(book,0,sizeof(book)); ncount=0; ki=0; mi=n+1; first=1; while(ncount!=n){ kcount=0; mcount=0; while(kcount!=k){ ki++; if(ki>n) ki=1; if(book[ki]==0) kcount++; } while(mcount!=m){ mi--; if(mi<1) mi=n; if(book[mi]==0) mcount++; } book[ki]=1; book[mi]=1; if(first){ first=0; if(ki!=mi){ printf("%3d%3d",ki,mi); ncount+=2; } else{ printf("%3d",ki); ncount++; } }else{ if(ki!=mi){ printf(",%3d%3d",ki,mi); ncount+=2; } else{ printf(",%3d",ki); ncount++; } } } printf("\n"); } return 0; }
|