[백준] 15828 Router

0

백준

목록 보기
193/271
post-thumbnail

[백준] 15828 Router

#include <queue>
#include <iostream>
using namespace std;

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL); cout.tie(NULL);

	int n;
	cin >> n;

	queue<int> router;

	while (true) {
		int input;
		cin >> input;
		if (input == -1) break;
		
		//패킷 처리
		if (input == 0) router.pop();

		//패킷 도착
		else if (router.size() < n) router.push(input);
	}
	
	if (router.empty()) cout << "empty";
	else {
		while (!router.empty()) {
			cout << router.front()<<" ";
			router.pop();
		}
	}
	return 0;
}
profile
Be able to be vulnerable, in search of truth

0개의 댓글