josephus I done but II is not that easy

This commit is contained in:
2024-06-20 20:55:11 +02:00
parent 0846a55574
commit 08c87b425b
3 changed files with 50 additions and 1 deletions

View File

@@ -0,0 +1,26 @@
// Josephus Problem I
#include<bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int n; cin >> n;
queue<int> children;
for (int i = 1; i <= n; i++) children.push(i);
bool flag = true;
while (!children.empty()) {
int ele = children.front();
children.pop();
if (flag) {
children.push(ele);
} else {
cout << ele << " ";
}
flag = !flag;
}
return 0;
}