본문 바로가기

알고리즘

[C++] BOJ-1012

 

 

문제풀이


기본적인 Queue 문제

#include <iostream>
#include <algorithm>
#include <queue>

using namespace std;


int main(){
	ios_base :: sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
	queue <int> q;
	
	int N, M;
	cin >> N >> M;
	
	for(int i = 0; i<N; i++){
		q.push(i+1);
	}
	
	cout << "<";
	for(int i = 0; i<N; i++){
		for(int j = 0; j<M-1; j++){
			q.push(q.front());
			q.pop();
		}
		if(i == N-1){
			cout << q.front() << ">";
		}else{
			cout << q.front() << ", ";
			q.pop();
		}

	}
	
	
}

'알고리즘' 카테고리의 다른 글

[C++] BOJ-1238  (0) 2019.10.11
[C++] BOJ-1012  (0) 2019.10.11
[C++] BOJ-1012  (0) 2019.10.11
[C++] BOJ-7576  (0) 2019.09.09
[C++] BOJ-4963 문제풀이  (0) 2019.09.09