[백준] 1158 요세푸스 문제

0

백준

목록 보기
151/271
post-thumbnail
post-custom-banner

[백준] 1158 요세푸스 문제

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

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL); cout.tie(NULL);

	int n, k;
	cin >> n >> k;

	queue<int> circle;
	for (int i = 1; i <= n; ++i) {
		circle.push(i);
	}

	vector<int> vec;
	while (!circle.empty()) {
		for (int i = 0; i < k-1; ++i) {
			circle.push(circle.front());
			circle.pop();
		}
		vec.push_back(circle.front());
		circle.pop();
	}

	cout << "<";
	for (int i = 0; i < n-1; ++i) {
		cout << vec[i] << ", ";
	}
	cout << vec[n - 1] << ">";

	return 0;
}

profile
Be able to be vulnerable, in search of truth
post-custom-banner

0개의 댓글