此题注意开始是从start开始数,但是后来都是从删除的接下来一个开始数,因此先要排除第start个之前的人
然后就都是一个规律了,这里使用了c++的new和delete,直接获得一个指向结构体的指针
#include<stdio.h>
struct kids
{
char name[20];
kids *next;
};
int main()
{
int n;
scanf("%d",&n);
kids *head=NULL,*p1,*p2;
for(int i=1;i<=n;i++){
p1=new kids;
scanf("%s",p1->name);
if(head==NULL)
head=p1;
else
p2->next=p1;
p2=p1;
}
p1->next=head;
int start,endn;
scanf("%d,%d",&start,&endn);
for(int i=1;i<=start-1;i++)
p1=p1->next;
for(int i=1;i<=n;i++){
for(int j=1;j<endn;j++)
p1=p1->next;
printf("%s\n",p1->next->name);
delete p1->next;
p1->next=p1->next->next;
}
return 0;
}