萌新手打链表但是发现后几个输出会出现重复数字??

P1996 约瑟夫问题

建议用对列(有代码) ```cpp #include <iostream> #include <queue> using namespace std; queue<int> q; int main(){ int n, k; cin >> n >> k; for (int i = 1; i <= n; i ++){ q.push(i); } while (!q.empty()){ for (int i = 0; i < k - 1; i ++){ q.push(q.front()); q.pop(); } cout << q.front() << " "; q.pop(); } return 0; } `````` 本人为四年级小朋友
by garyzhao @ 2023-08-15 16:33:44


我不是大佬(因为我根本看不懂)
by garyzhao @ 2023-08-15 16:34:48


|