C++ 实现约瑟夫环问题:模拟扔牌游戏
#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/np6f 著作权归作者所有。请勿转载和采集!