Little Jay

[C++] 백준 1316번 요세푸스 문제 본문

알고리즘/BOJ

[C++] 백준 1316번 요세푸스 문제

Jay, Lee 2021. 5. 4. 16:15

저번에 푼 요세푸스문제 0과 동일하다

#include <iostream>
#include <queue>
using namespace std;

int main() {

	cin.tie(0);
	cout.tie(0);
	ios::sync_with_stdio(false);

	int n, k;
	queue<int> q;
	cin >> n >> k;

	for (int i = 1; i <= n; i++) {
		q.push(i);
	}

	cout << "<";

	while (!q.empty()) {
		for (int i = 0; i < k - 1; i++) {
			q.push(q.front());
			q.pop();
		}

		cout << q.front();
		q.pop();

		if (!q.empty()) {
			cout << ", ";
		}
	}
	cout << ">" << "\n";


	return 0;
}

 

Comments