/*
根据题意,很容易理解,因为是第一张扔掉,第二张放在最后,所以相当于是在扔牌的时候每次前进两步,每一步都是没有被扔过的牌
*/
#include
#include
#include
#include
#include
using namespace std;
int main()
{
int n,a[55],pos,cnt;
while(scanf("%d",&n)!=EOF&&n){
pos=0;
printf("Discarded cards:");
for(int i=0;i1;
for(int i=0;i+1
if(i)printf(",");
printf(" %d",a[pos]);
a[pos]=0,cnt=2;
while(cnt){
if(a[pos])--cnt;
if(cnt)pos=(pos+1)%n;
}
}
for(pos=0;posif(a[pos])break;
printf("\nRemaining card: %d\n",a[pos]);
}
return 0;
}
/*
方法二是按照题意的要求,很容易想到使用双端队列
*/
#include
#include
#include
#include
#include
#include
using namespace std;
int main()
{
int n;
while(scanf("%d",&n)!=EOF&&n){
dequeq;
printf("Discarded cards:");
for(int i=0;i for(int i=0;i+1 if(i)printf(",");
printf(" %d",q.front());
q.pop_front();
q.push_back(q.front());
q.pop_front();
}
printf("\nRemaining card: %d\n",q.front());
}
return 0;
}