#include <iostream>
#include <string>
#include <queue>
using namespace std;
queue<int> q;
string res;
void Push(int x) { q.push(x); }
void Pop()
{
if (q.empty())
res += to_string(-1) + '\n';
else
{
res += to_string(q.front()) + '\n';
q.pop();
}
}
void Size() { res += to_string(q.size()) + '\n'; }
void Empty() { res += to_string(q.empty() ? 1 : 0) + '\n'; }
void Front() { res += to_string(q.empty() ? -1 : q.front()) + '\n'; }
void Back() { res += to_string(q.empty() ? -1 : q.back()) + '\n'; }
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int n; cin >> n;
for (size_t i = 0; i < n; i++)
{
string s; cin >> s;
if (s == "push")
{
int tmp; cin >> tmp;
Push(tmp);
}
else if (s == "pop")
Pop();
else if (s == "size")
Size();
else if (s == "empty")
Empty();
else if (s == "front")
Front();
else
Back();
}
res.pop_back();
cout << res;
return 0;
}
'코딩테스트 > 백준' 카테고리의 다른 글
[실4] 28278 - 스택 2 (0) | 2023.08.29 |
---|---|
[실5] 2563 - 색종이 (0) | 2023.08.28 |
[실4] 10816 - 숫자 카드 2 (0) | 2023.08.28 |
[실4] 2003 - 수들의 합2 (0) | 2023.08.13 |
[골4] 1197 - 최소 스패닝 트리 (0) | 2023.08.12 |