1 #include <stdlib.h> 2 #include <stdio.h> 3 typedef struct node* link; 4 struct node {int item;link next;}; 5 int main (int argc, char *argv[]){ 6 7 int i, N=atoi(argv[1]), M=atoi(argv[2]); 8 link t=malloc(sizeof *t), x=t; 9 t->item =1; t->next=t; 10 11 for(i=2;i<=N;i++){ 12 x=(x->next=malloc(sizeof *x)); 13 x->item=i;x->next=t; 14 15 } 16 x=t; 17 printf("%d,%d\n",x->item,x->next->item); 18 while(x!=x->next){ 19 for(i=1;i<M-1;i++) x=x->next; 20 printf("NO:%d is out,%d left\n",x->next->item,--N); 21 x->next=x->next->next; x=x->next; 22 23 24 } 25 printf("%d is winner\n",x->item); 26 return 0; 27 28 } 29 30 31 32

浙公网安备 33010602011771号