#define N 25
struct student{
int flag;
struct student* next;
};
int main()
{
int i=1; //Ñ-»·¼Æêy£»
int j=1;
struct student * head; //á′±íμÄí·Ö¸Õ룻
struct student * p; //½¨±íμÄáùê±Ö¸Õ룻
struct student *q; //Ç°ò»¸öÖ¸Õ룻
struct student *end; //Ñ-»·ÖDóÃμ½£»
int values[N+1]={0}; //¼Ç¼ÿò»¸öèËμúò»′α¨êyμÄêy×ÖμÄÖμ¡£¡£
p=(struct student*)malloc(sizeof(struct student));
head=p;
q=p;
p->flag=i;
p->next=NULL;
i++;
//1½¨á¢á′±í£»
while(i<=N)
{
p=(struct student*)malloc(sizeof(struct student));
p->flag=i;
p->next=NULL;
q->next=p;
q=p;
i++;
}
q->next=head; //×é3éò»¸öÔ2è|¡£¡£
end=q; //Ñ-»·ÖDóÃμ½£»
i=25;
//2Ñ-»·Çó½aμÄ1y3죻
while(i>1)
{
if(values[head->flag]==0)
{
values[head->flag]=j;
}
if(j%3==0)
{//é¾3y¸Ã½úμ㣻
p=head;
head=head->next;
end->next=head;
free(p);
j++;
i--;
}
else{
end=head;
head=head->next;
j++;
}
}
printf("%d\n",values[head->flag]);
return 0;
}
楼主自己加上头文件,试试。。。。。运行结果为14.最终剩下的就是地14个人。。而且用的是单链表。。。。
struct student{
int flag;
struct student* next;
};
int main()
{
int i=1; //Ñ-»·¼Æêy£»
int j=1;
struct student * head; //á′±íμÄí·Ö¸Õ룻
struct student * p; //½¨±íμÄáùê±Ö¸Õ룻
struct student *q; //Ç°ò»¸öÖ¸Õ룻
struct student *end; //Ñ-»·ÖDóÃμ½£»
int values[N+1]={0}; //¼Ç¼ÿò»¸öèËμúò»′α¨êyμÄêy×ÖμÄÖμ¡£¡£
p=(struct student*)malloc(sizeof(struct student));
head=p;
q=p;
p->flag=i;
p->next=NULL;
i++;
//1½¨á¢á′±í£»
while(i<=N)
{
p=(struct student*)malloc(sizeof(struct student));
p->flag=i;
p->next=NULL;
q->next=p;
q=p;
i++;
}
q->next=head; //×é3éò»¸öÔ2è|¡£¡£
end=q; //Ñ-»·ÖDóÃμ½£»
i=25;
//2Ñ-»·Çó½aμÄ1y3죻
while(i>1)
{
if(values[head->flag]==0)
{
values[head->flag]=j;
}
if(j%3==0)
{//é¾3y¸Ã½úμ㣻
p=head;
head=head->next;
end->next=head;
free(p);
j++;
i--;
}
else{
end=head;
head=head->next;
j++;
}
}
printf("%d\n",values[head->flag]);
return 0;
}
楼主自己加上头文件,试试。。。。。运行结果为14.最终剩下的就是地14个人。。而且用的是单链表。。。。