(1.1.7)UVA 10935 Throwing cards away I(直叙式模拟)

来源:互联网 发布:刘涛直播网络瘫痪 编辑:程序博客网 时间:2024/05/20 13:08
#include <iostream>#include <queue>#include <cstdio>using namespace std;int main() {int n;const int maxn = 55;int ans[maxn];while (scanf("%d", &n) != EOF, n) {int i;queue<int> q;for (i = 1; i <= n; ++i) {q.push(i);}int k = 0;while (!q.empty()) {ans[k++] = q.front();q.pop();if (!q.empty()) {int t = q.front();q.pop();q.push(t);}else{break;}}printf("Discarded cards:");for (i = 0; i < n - 1; ++i) {printf(i < n - 2 ? " %d," : " %d", ans[i], ans[i]);}printf("\nRemaining card: %d\n", ans[n - 1]);}return 0;}

原创粉丝点击