#include<iostream> #include<queue> using namespace std; int main() { int n; while(scanf("%d", &n) && n) { queue<int> q, ans; for(int i = 1; i <= n; i++) q.push(i); while(q.size() > 1) { ans.push(q.front()); q.pop(); q.push(q.front()); q.pop(); } cout << "Discarded cards:"; for (int i = 0; i < n - 1;i++) { printf(" %d",ans.front()); if(i < n - 2) printf(","); ans.pop(); } cout << endl; printf("Remaining card: %d\n",q.front()) ; } }
UVA-10935 Throwing cards away I 【队列+模拟】
猜你喜欢
转载自blog.csdn.net/qq_37602930/article/details/80067062
今日推荐
周排行