#include<stdio.h>
typedef struct node{
int num;
int password;
struct node *next;
}node,*linklist;
void initlist(linklist l)
{linklist t;
t=(linklist)malloc(sizeof(node));
t->num=0;t->password=0;
l=t;t->next=l;}
int delet_link_sqlist(linklist l,int m)
{int a,b;
linklist p,q,r;
p=l;
for(r=l;r->next!=l;r=r->next);
if(m==1)
{ q=l->next;
l->next=q->next;}
else
{for(a=2;a<=m;a++)
{p=p->next;
if(p==l) p=l->next;}
if(p->next==l){ q=l->next;
l->next=q->next;}
else
{q=p->next;
p->next=l;
r->next=l->next;
l->next=q->next;}}
b=q->password;
printf("%d ",q->num);
return b;
free(q);}
void insert(linklist l,int n)
{int i=1,j;
linklist p,t;
p=l;
while(i<=n)
{scanf("%d",&j);
t=(linklist)malloc(sizeof(node));
t->num=i;t->password=j;
p->next=t;t->next=l;p=t;
i++;}}
main()
{int n,m;
linklist l;
printf("please input n and m:");
scanf("%d%d",&n,&m);
printf("please input the %d people's password:",n);
initlist(l);
insert(l,n);
printf("the people's code is:");
while(l->next!=l)
m=delet_link_sqlist(l,m);}