1 #include <stdio.h> 2 #include <stdlib.h> 3 #define NUM 5 //游戏人数 4 #define OUT 3 // 逢3出局 5 struct Person 6 { 7 int num; 8 struct Person *next; 9 }; 10 int main() 11 { int i,j; 12 int cnt=1; 13 int index=0; 14 int c[NUM]={0}; 15 struct Person person[NUM],*p; 16 printf("\n游戏人数是 %d 人\n逢 %d 出局\n\n",NUM,OUT); 17 for(i=0;i<NUM;i++) 18 { 19 person[i].num=i+1; 20 person[i].next=&person[(i+1)%NUM]; 21 } 22 p=&person[0]; 23 while((p->num)!=(p->next->num)) 24 { 25 while(cnt<OUT-1) 26 { 27 p=p->next; 28 cnt++; 29 } 30 c[index]=p->next->num; 31 index++; 32 p->next=p->next->next; 33 p=p->next; 34 cnt=1; 35 } 36 c[index]=p->num; 37 printf("最后一个人是:%d\n\n",p->num); 38 printf("出局的顺序是:\n"); 39 for(j=0;j<NUM;j++) 40 { 41 printf("-->%d",c[j]); 42 } 43 printf("\n\n"); 44 system("pause"); 45 return 0; 46 }
原文:http://www.cnblogs.com/houjun/p/4859876.html