#include "stdio.h"
#include "string.h"
struct people
{
int num;
struct people *next;
};
struct people *create(int n)
{
struct people *head=NULL,*p=NULL,*tail=NULL;
int i;
for(i=1;i<=n;i++)
{ p=(struct people *)malloc(sizeof(struct people));
p->num=i;p->next=NULL;
if(i==1)
{head=p;}
else
{tail->next=p;}
tail=p;
}
tail->next=head;
return head;
}
struct people *del(struct people *head)
{struct people *p1=head,*q=NULL;
int i=1;
while(p1->next!=p1)
{ if(i==3)
{
q->next=p1->next;
p1->next=NULL;
free(p1);
p1=q->next;
i=1;
}
else
{q=p1;
p1=p1->next;
i++;
}
}
return p1->num;
}
main()
{
int n,k;
struct people *head,*p;
scanf("%d",&n);
if(n==1)
{printf("1");
return 0;}
else
{head=create(n);
k=del(head);
printf("%d",k);
}
}
上一篇刚刚不小心发错了