您的位置:首页 > 其它

Throwing cards away I UVA - 10935

2017-04-11 15:55 639 查看
问题类型: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;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: