백준

[1158], [11866] 조세퍼스 문제

Jcoder 2018. 7. 22. 17:36


#include <iostream>
#include <queue>
#include <string>
using namespace std;
void Josephus(int n, int m);
int main()
{
int n, m;
cin >> n >> m;
Josephus(n, m);
return 0;
}
void Josephus(int n, int m)
{
queue<int> q;
int i;
for (i = 1; i <= n; i++)
q.push(i);
cout << "<";
while (!q.empty())
{
for (i = 0; i < m - 1; i++)
{
q.push(q.front());
q.pop();
}
cout << q.front();
q.pop();
if (!q.empty())
cout << ", ";
}
cout << ">\n";
return;
}