728x90
반응형
#include <iostream>
#include <queue>
#include <string>
using namespace std;
int main()
{
ios::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
int N;
cin >> N;
queue<int> q;
while (N--)
{
string command;
cin >> command;
if (command == "push")
{
int x;
cin >> x;
q.push(x);
}
else if (command == "pop")
{
if (q.empty())
{
cout << -1 << "\n";
}
else
{
cout << q.front() << "\n";
q.pop();
}
}
else if (command == "size")
{
cout << q.size() << "\n";
}
else if (command == "empty")
{
cout << (q.empty() ? 1 : 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";
}
}
}
return 0;
}
728x90
반응형
'Baekjoon > Silver' 카테고리의 다른 글
Baekjoon 2003.수들의 합2 c++ [Silver IV] (0) | 2025.02.04 |
---|---|
Baekjoon 15650.N과 M (2) c++ [Silver III] (0) | 2025.01.09 |
Baekjoon 10816.숫자 카드 2 c++ [Silver IV] (0) | 2024.12.30 |
Baekjoon 1436.영화감독 슘 c++ [Silver V] (0) | 2024.12.28 |
Baekjoon 17219.비밀번호 찾기 c++ [Silver IV] (0) | 2024.12.23 |