#include<stdio.h>
#include<malloc.h>
typedef struct node
{ int num;
int password;
struct node *next;
}node;
node head;
node *h=&head;
void creat(int n)
{ int i=1;
node *p,*p1;
p=h;
printf("input the password:\n");
h->num=i;
scanf("%d",&h->password);
while(i<n)
{ i++;
p1=(node*)malloc(sizeof(node));
p1->num=i;
scanf("%d",&p1->password);
p->next=p1;
p1->next=h;
p=p1;
}
}
main()
{ int i,n,m;
node *pre=h;
printf("input the people's num:\n");
scanf("%d",&n);
printf("input the initiate values:\n");
scanf("%d",&m);
creat(n);
i=1;
while(h->next!=h)
{ if(i==m)
{ printf("number:%d\n",h->num);
m=h->password;
pre->next=h->next;
h=pre->next;
i=1;
}
else
{ pre=h;
h=h->next;
i++;
}
}
printf("number:%d\n",h->num);
}