1158_요세푸스(C++)

2594 단어 큐(Queue)큐(Queue)

	#include <iostream>
	#include<queue>
	using namespace std;
	
	int main() {
		int N, K;
		string command;
		queue<int> mine;
		queue<int> result;
		cin >> N >> K;
		for (int i = 1; i <= N; i++) {
			mine.push(i);
		}
		while (!mine.empty()) {
			for (int i = 0; i < K-1; i++) {
				int j = mine.front();
				mine.pop();
				mine.push(j);
			}
			result. push(mine.front());
			mine.pop();
		}
		cout << '<';
		while (!result.empty()) {
			if (result.size() != 1) cout << result.front() << ", ";
			else cout << result.front();
			result.pop();
		}
		cout << '>';
	}

큐 설명 참고:
https://velog.io/@kimeunseo58/%ED%81%90
큐 소스코드:
https://velog.io/@kimeunseo58/10845%ED%81%90C

좋은 웹페이지 즐겨찾기