알고리즘/BaekJoon
[c++] 11866번 : 요세푸스 문제 0
__jhp_+
2022. 5. 12. 14:56
https://www.acmicpc.net/problem/11866
11866번: 요세푸스 문제 0
첫째 줄에 N과 K가 빈 칸을 사이에 두고 순서대로 주어진다. (1 ≤ K ≤ N ≤ 1,000)
www.acmicpc.net
#include <iostream>
#include <queue>
using namespace std;
int main()
{
ios::sync_with_stdio(false);
cin.tie(NULL);
queue<int> q;
int N = 0, K = 0;
cin >> N >> K;
for (int i = 0; i < N; ++i)
{
q.push(i + 1);
}
cout << '<';
while (q.empty() == false)
{
for (int i = 1; i < K; ++i)
{
q.push(q.front());
q.pop();
}
cout << q.front();
q.pop();
if (q.empty() == false)
{
cout << ", ";
}
}
cout << '>' << '\n';
return 0;
}