Sample Output
2
6
132
#include <iostream>
#include"cstdio"
#include"cstring"
#include"cstdlib"
using namespace std;
struct gsd
{
int num;
gsd *next;
}*head;
int main()
{int n;
while(~scanf("%d",&n))
{if(n==0)break;
gsd *p,*q;
head=(gsd*)malloc(sizeof(gsd));
head->next=NULL;
q=head;
for(int i=1;i<=n;i++)
{
p=(gsd*)malloc(sizeof(gsd));
p->num=i;
q->next=p;
q=p;
}
q->next=head->next;
int c1=0,c2=0;
q=head->next;
while(1)
{
c1++;
if(c1==5)
{
c2++;c1=0;
if(q->num==1)break;
else
{p->next=q->next;
free(q);
q=p->next;
continue;
}
}
p=q;
q=q->next;
}
printf("%d\n",c2);
}
return 0;
}
649

被折叠的 条评论
为什么被折叠?



