要求:
桌上有一叠牌,从上到下一次编号1~n当至少剩两张牌时进行以下操作:
扔掉第一张牌,把新的第一张放到最后,输出扔掉的牌编号和剩下的牌编号
sample input:
7
sample output:
1 3 5 7 4 2 6
code:
View Code
#include<stdio.h>
const int maxn=100;
int queue[maxn];
int main()
{
int front,rear,i,n;
while(scanf("%d",&n)!=EOF)
{
for(i=1;i<=n;i++)
queue[i]=i;
front=0;
rear=n;
while(front<rear)
{
printf("%d ",queue[++front]);
queue[++rear]=queue[++front];
}
}
return 0;
}