问题类型:STL-queue应用。
03pie’s solution for [UVA-10935]
问题链接
#include<iostream>
#include<queue>using namespace std;const int maxn=50;int main(){//freopen("F://inp.txt","r",stdin);int n;while(cin>>n&&n){queue<int> cards;for(int i=0;i<n;i++){cards.push(i+1);}int len=cards.size();cout<<"Discarded cards:";if(len>1){while(--len){cout<<" "<<cards.front();//输出队首元素 if(len>1) cout<<",";cards.pop();//队首出队 cards.push(cards.front());//将新队首元素放在队尾 cards.pop();//队首出队 }}
// else cout<<cards.front();cout<<"\nRemaining card: "<<cards.front()<<endl;}return 0;
}