n个人围成一个圆桌,按照顺时针的顺序1,2,……n进行编号;某一个人开始报一个数字,然后顺时针的下一个人会报数+1;当某个人报的数字含有7或是7的倍数时,这个人退出游戏,其他人接着报数!直到剩下一个人为止!
》输入
输入n,m,t;n代表人数,m代表开始报数的人的编号;t表示开始报数的人报出的数字是t;
然后接下来有n行,是这n个人的名字!
》输出
输出最后一个人的名字!
》样例输入:
5 3 20
liming
wangze
gongxiangjun
wangming
chenzhen
》样例输出:
Chenzhen
我写的:
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
typedef struct node
{
char name[20];
struct node *next;
}node;
typedef struct
{
node *front;
node *rear;
}LQ;
LQ * csh()
{
LQ *p;
p=(LQ *)malloc(sizeof(LQ));
p->front=(node *)malloc(sizeof(node));
p->front->next=NULL;
p->rear=p->front;
return p;
}
LQ * in(LQ *Q,char a[])
{
node *p;
p=(node *)malloc(sizeof(node));
strcpy(p->name,a);
p->next=NULL;
Q->rear->next=p;
Q->rear=p;
return Q;
}
void run(LQ *Q,int n,int m,int t)
{
node *p,*q;
q=Q->front;
p=q->next;
while(--m)
{
q=p;
p=q->next;
}
while(n!=1)
{
if(t%7==0)
{
if(p==Q->rear)
{
q->next=NULL;
Q->rear=q;
q=Q->front;
p=q->next;
}
else
{
q->next=p->next;
p=q->next;
}
n--;
}
else
{
if(p==Q->rear)
{
q=Q->front;
p=q->next;
}
else
{
q=p;
p=q->next;
}
}
t++;
}
printf("%s",p->name);
}
int main()
{
int n,m,t;
char a[20];
LQ *Q;
Q=csh();
scanf("%d %d %d",&n,&m,&t);
int i=n;
while(i--)
{
scanf("%s",a);
in(Q,a);
}
run(Q,n,m,t);
return 0;
}
输出的是第一个名字
请求帮忙看看问题出在哪🤔