Memo
풀이 생략!!
Code
제출 날짜
@4/19/2021
메모리
2156 KB
시간
4 ms
#include <iostream>
#include <queue>
#include <string>
int N;
std::string s;
std::queue<int> que;
std::vector<int> result;
// push, pop, size, empty, front, back
void output()
{
for (auto &i : result)
std::cout << i << '\n';
}
void solution()
{
int num;
if (s == "push")
{
std::cin >> num;
que.push(num);
}
else if (s == "pop")
{
if(que.empty())
{
result.push_back(-1);
}
else
{
result.push_back(que.front());
que.pop();
}
}
else if (s == "size")
result.push_back(que.size());
else if (s == "empty")
{
if (que.empty())
result.push_back(1);
else
result.push_back(0);
}
else if (s == "front")
{
if (que.empty())
result.push_back(-1);
else
result.push_back(que.front());
}
else
{
if (que.empty())
result.push_back(-1);
else
result.push_back(que.back());
}
}
void input()
{
std::cin >> N;
for (int i = 0; i < N; ++i)
{
std::cin >> s;
solution();
}
}
void preset()
{
std::ios_base::sync_with_stdio(false);
std::cin.tie(NULL);
std::cout.tie(NULL);
}
int main()
{
preset();
input();
output();
}
C++
복사