#include <bits/stdc++.h>
using namespace std;
/*
========================
🟢 문제 1: 기본 큐 회전
========================
설명:
1부터 N까지 큐에 넣는다.
K번 반복:
- 맨 앞 출력 후 제거
- 다음 원소를 뒤로 이동
입력:
N K
예시:
5 3
출력:
1 3 5
*/
void problem1() {
int N, K;
cin >> N >> K;
queue<int> q;
for (int i = 1; i <= N; i++) q.push(i);
for (int i = 0; i < K; i++) {
cout << q.front() << " ";
q.pop();
if (!q.empty()) {
q.push(q.front());
q.pop();
}
}
}
/*
========================
🟡 문제 2: 요세푸스 Lite
========================
설명:
1부터 N까지 큐
매번 K번째 사람 제거
입력:
N K
예시:
7 3
출력:
3 6 2 7 5 1 4
*/
void problem2() {
int N, K;
cin >> N >> K;
queue<int> q;
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();
}
}
/*
========================
🔴 문제 3: 조건부 제거 큐
========================
설명:
1부터 N까지 큐
카운트 증가하면서:
- K의 배수면 제거
- 아니면 뒤로 이동
입력:
N K
예시:
5 2
출력:
2 4 1 5 3
*/
void problem3() {
int N, K;
cin >> N >> K;
queue<int> q;
for (int i = 1; i <= N; i++) q.push(i);
int cnt = 1;
while (!q.empty()) {
int cur = q.front();
q.pop();
if (cnt % K == 0) {
cout << cur << " ";
} else {
q.push(cur);
}
cnt++;
}
}
/*
========================
실행 선택
========================
원하는 문제 함수 하나만 실행
*/
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
// problem1();
// problem2();
// problem3();
return 0;
}
To embed this project on your website, copy the following code and paste it into your website's HTML: