https://www.acmicpc.net/problem/18258
#include <bits/stdc++.h>
#define endl "\n"
using namespace std;
void CPP_INIT() {
ios::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
}
int main(void) {
CPP_INIT();
int input;
int num;
string str;
queue<int> qu;
cin >> input;
for (int i = 0; i < input; i++) {
cin >> str;
if (str.find("push") != -1) {
cin >> num;
qu.push(num);
}
else if (str == "pop") {
if (qu.empty()) cout << -1 << endl;
else {
num = qu.front();
qu.pop();
cout << num << endl;
}
}
else if (str == "size") {
cout << qu.size() << endl;
}
else if (str == "empty") {
cout << qu.empty() << endl;
}
else if (str == "front") {
if (qu.empty()) cout << -1 << endl;
else cout << qu.front() << endl;
}
else if (str == "back") {
if (qu.empty()) cout << -1 << endl;
else cout << qu.back() << endl;
}
}
}
'알고리즘' 카테고리의 다른 글
C++ 알고리즘 - 백준 2346 풍선 터뜨리기 (0) | 2025.01.12 |
---|---|
C++ 알고리즘 - 백준 28279 덱 2 (0) | 2025.01.12 |
C++ 알고리즘 - 백준 12789 도키도키 간식드리미 (0) | 2025.01.12 |
C++ 알고리즘 - 백준 28728 스택 2 (0) | 2025.01.12 |
C++ 알고리즘 - 백준 17103 골드바흐 파티션 (에라토스테네스의 체) (0) | 2025.01.12 |