用C++写:桌面有一叠牌从第一张即位于顶面的牌开始从上往下依次编号为1∼n。当至少还剩两张牌时进行以下操作:把第一张牌扔掉然后把新的第一张放到整叠牌的最后。输入n输出每次扔掉的牌以及最后剩下的牌 3≤n≤100。
#include 
int main() { int n; cin >> n;
queue<int> q;
for (int i = 1; i <= n; i++) {
    q.push(i);
}
while (q.size() > 1) {
    int first = q.front();
    q.pop();
    cout << first << " ";
    int second = q.front();
    q.pop();
    q.push(second);
}
cout << q.front() << endl;
return 0;
}
原文地址: https://www.cveoy.top/t/topic/b8SF 著作权归作者所有。请勿转载和采集!