[백준] 10845 큐

0

백준

목록 보기
155/271
post-thumbnail
post-custom-banner

[백준] 10845 큐

#include <string>
#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> q;
	while (n--) {
		string op;
		cin >> op;
		if (op == "push") {
			int x;
			cin >> x;
			q.push(x);
		}
		else if (op == "pop") {
			if (q.empty()) cout << -1<<"\n";
			else {
				cout << q.front() << "\n";
				q.pop();
			}
		}
		else if (op == "size") {
			cout << q.size() << "\n";
		}
		else if (op == "empty") {
			cout << q.empty() << "\n";
		}
		else if (op == "front") {
			if (q.empty()) cout << -1 << "\n";
			else cout << q.front() << "\n";
			
		}
		else if (op == "back") {
			if (q.empty()) cout << -1 << "\n";
			else cout << q.back() << "\n";
		}
	}

	return 0;
}

profile
Be able to be vulnerable, in search of truth
post-custom-banner

0개의 댓글