#include <stdio.h>#include <stdlib.h>
typedef struct people
{
int num ;
struct people *next ;
}people ;
people *insert_new ()
{
people *p ;
p = (people *)malloc(sizeof (people)) ;
return p ;
}
int main ()
{
int i , num , count = 1 ;
people *a , *h ;
printf ("输入人数:") ;
scanf ("%d" , &num) ;
a = h = (people *)malloc(sizeof (people)) ;
a ->num = 1 ;
i= 2 ;
while (i <= num)
{
a ->next = insert_new() ;
a = a ->next ;
a ->num = i ;
i++ ;
}
a ->next = h ;
while ( h ->next != h)
{
if (count == 2)
{
printf ("%d退出\n" , h ->next ->num) ;
h ->next = h ->next ->next ;//报数为3的退出,重新开始计数。
count = 0 ;
}
h = h ->next ;
count++ ;
}
printf ("最后剩下的人序号为%d\n" , h ->num) ;
return0 ;
}