解题思路:queue应用
解题代码:
#include<iostream>
#include<map>
#include<cstdio>
#include<sstream>
#include<queue>
#include<vector>
#include<cstring>
#include<algorithm>
using namespace std;
int main(){
int n;
while((cin>>n)&&n){
queue<int>q;
cout<<"Discarded cards: ";
for(int i=1;i<=n;i++) q.push(i);
if(n==1) puts("");
else{
while(1){
int t=q.front();
q.pop();
if(q.size()==1){
cout<<t<<endl;
break;
}
else{
cout<<t;
}
cout<<", ";
t=q.front();
q.pop();
q.push(t);
}
}
cout<<"Remaining card: "<<q.front()<<endl;
q.pop();
}
return 0;
}