您的位置:首页 > 其它

UVa 10935 - Throwing cards away I

2014-12-09 17:04 561 查看
队列的简单应用,PE了两次。

#include<iostream>
#include<queue>
using namespace std;

int main() {
int n;
while(cin >> n&& n) {
bool sign = false;
queue<int> q;
for(int i = 1; i <= n; i++)
q.push(i);
cout << "Discarded cards:";
while(q.size() != 1) {
sign ? cout << ", " : cout << " ";
sign = true;
cout << q.front();
q.pop();
if(q.size() == 1)
break;
q.push(q.front());
q.pop();
}
cout << endl << "Remaining card: " << q.front() << endl;
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: