当前位置: 代码迷 >> 综合 >> Throwing cards away I UVA - 10935
  详细解决方案

Throwing cards away I UVA - 10935

热度:4   发布时间:2023-10-13 14:48:47.0

问题类型: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;
}
  相关解决方案