- 문제
- 풀이
#include <iostream>
#include <queue>
using namespace std;
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
int N = 0;
cin >> N;
queue<int> q;
while (N--)
{
string cmd = "";
cin >> cmd;
if (cmd == "push")
{
int input = 0;
cin >> input;
q.push(input);
}
else if (cmd == "pop")
{
if (!q.empty())
{
cout << q.front() << '\n';
q.pop();
}
else
{
cout << -1 << '\n';
}
}
else if (cmd == "size")
{
cout << q.size() << '\n';
}
else if (cmd == "empty")
{
if (!q.empty())
{
cout << 0 << '\n';
}
else
{
cout << 1 << '\n';
}
}
else if (cmd == "front")
{
if (!q.empty())
{
cout << q.front() << '\n';
}
else
{
cout << -1 << '\n';
}
}
else if (cmd == "back")
{
if (!q.empty())
{
cout << q.back() << '\n';
}
else
{
cout << -1 << '\n';
}
}
}
return 0;
}
'코딩테스트 > 문제풀이' 카테고리의 다른 글
[백준/2504번/C++] 괄호의 값 (1) | 2024.11.12 |
---|---|
☆ [백준/1926번/C++] 그림 (+ BFS 개념과 핵심) (0) | 2024.11.11 |
[백준/2443번/C++] 별 찍기 - 6 (0) | 2024.11.09 |
[백준/2164번/C++] 카드 2 (0) | 2024.11.08 |
[백준/2442번/C++] 별 찍기 - 5 (0) | 2024.11.07 |