一周纪念,我恶梦缠绕的约瑟夫环...
下一站.?


#include <stdio.h>
#include <stdlib.h>
typedef struct people
  {
   int num;
   int password;
   struct people *next;
  }peo;
 main()
 {
  int i,n,k=1;
     int j,a,b;
     printf("请输入参与人数:\n");
     scanf("%d",&i);
  if(i==0)printf("人数不够\n");
  else
  {
   peo *l,*p,*q,*z;
      p=(peo*)malloc(sizeof(peo));
      p->num=k;
      printf("%d的号码\n",k);
      scanf("%d",&p->password);
      l=p;

   if(i==1)
   { printf("请输入起始号:\n");
               scanf("%d",&j);
    printf("第1个人退出,密码是%d\n",p->password);
   }
  
      else
   {
    for(k=2;k<=i;k++)
    {
         q=p;
               p=(peo*)malloc(sizeof(peo));
               q->next=p;
               p->num=k;
               printf("%d的密码:\n",k);
               scanf("%d",&p->password);
    };
               p->next=l;
               q=q->next;  
            p=p->next;
               printf("请输入起始号码:\n");
               scanf("%d",&j);
               n=i;
            while(n>1)
      {
              for(a=1;a<j;a++)
     {
                 q=p;
                          p=p->next;
     };
                    printf("第%d个人退出,他的密码为:%d\n",p->num,p->password);
                    j=p->password;
                    q->next=p->next;
                    free(p);
              p=q->next;
             
                n--;
      };
               printf("第%d个人退出,他的密码为:%d\n",p->num,p->password);
               printf("GAME OVER\n");
   };
  };
 }