본문 바로가기
백준

[10845] 큐

by Jcoder 2018. 7. 22.


#include <iostream>
#include <queue>
#include <string>
using namespace std;
int main()
{
queue<int> q;
int i, testcase;
string str;
cin >> testcase;
for (i = 0; i < testcase; i++)
{
cin >> str;
if (str == "push")
{
int num;
cin >> num;
q.push(num);
}
else if (str == "pop")
{
if (!q.empty())
{
cout << q.front() << endl;
q.pop();
}
else
cout << "-1\n";
}
else if (str == "size")
cout << q.size() << endl;
else if (str == "empty")
{
if (q.empty())
cout << "1\n";
else
cout << "0\n";
}
else if (str == "front")
{
if (!q.empty())
cout << q.front() << endl;
else
cout << "-1\n";
}
else if (str == "back")
{
if (!q.empty())
cout << q.back() << endl;
else
cout << "-1\n";
}
}
return 0;
}


'백준' 카테고리의 다른 글

[1158], [11866] 조세퍼스 문제  (0) 2018.07.22
[1966] 프린터 큐  (0) 2018.07.22
[2504] 괄호의 값  (0) 2018.07.22
[9012] 괄호  (0) 2018.07.22
[10828] 스택  (0) 2018.07.21