728x90
큐를 통해서 풀었습니다.
모든 값들을 큐에 차례대로 넣고 K-1만큼 큐에서 빼서 뒤로 보내고
K번째는 출력하고 pop해줍니다.
#include <iostream>
#include <cstring>
#include <algorithm>
#include <queue>
using namespace std;
int main(int argc, char *argv[])
{
int n, t;
int temp;
queue<int> q;
cin >> n >> t;
for (int i = 1; i <= n; ++i) {
q.push(i);
}
cout << "<";
while (1) {
for (int i = 0; i < t - 1; ++i) {
temp = q.front();
q.pop();
q.push(temp);
}
cout << q.front();
q.pop();
if (!q.size()) {
break;
}
cout << ", ";
}
cout << ">";
return 0;
}
'알고리즘' 카테고리의 다른 글
[C++] 백준 10808번 알파벳 개수 (0) | 2019.09.09 |
---|---|
[C++] 백준 2743번 단어 길이 재기 (0) | 2019.09.09 |
[C++] 백준 2312번 수 복원하기 (0) | 2019.09.09 |
[C++] 백준 2448번 별 찍기 - 11 (0) | 2019.09.09 |
[C++] 백준 2902번 KMP는 왜 KMP일까? (0) | 2019.09.09 |