본문 바로가기

BOJ

[백준] 10845번 큐 c++

#include <iostream>
#include <queue>
#include <string>
using namespace std;
int main(void) {
	int testCase;
	cin >> testCase;
	int num;
	string command;
	queue<int> q;
	for (int i = 0; i < testCase; i++) {
		cin >> command;
		if (command == "push") {
			cin >> num;
			q.push(num);
		}
		else if (command == "pop") {
			if (q.size()) {
				cout << q.front() << "\n";
				q.pop();
			}
			else
				cout << -1 <<"\n";
			
		}
		else if (command == "size") {
			cout << q.size() << "\n";
		}
		else if (command == "empty") {
			if (q.empty()) {
				cout << 1 << "\n";
			}
			else
				cout << 0 << "\n";
		}
		else if (command == "front") {
			if (q.empty()) {
				cout << -1 << "\n";
			}
			else
				cout << q.front() << "\n";
		}
		else if (command == "back") {
			if (q.empty()) {
				cout << -1 << "\n";
			}
			else
				cout << q.back() << "\n";
		}
	}
}

'BOJ' 카테고리의 다른 글

[백준] 2164번 카드2 c++  (0) 2020.04.23
[백준] 4월 23일 실버 달성  (0) 2020.04.23
[백준] 10828번 스택 c++  (0) 2020.04.23
[백준] 1406번 에디터 C++  (0) 2020.04.22
[백준] 1919번 애너그램 만들기 c++  (0) 2020.04.21