-
10845 본문
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <queue>
using namespace std;
int main()
{
int T = 0;
cin >> T;
queue<int> Q;
while (T--)
{
char cmd[10];
cin >> cmd;
if (!strcmp(cmd, "push"))
{
int num;
cin >> num;
Q.push(num);
}
else if (!strcmp(cmd, "pop"))
{
if (!Q.empty())
{
int tmp = Q.front();
cout << tmp << endl;
Q.pop();
}
else cout << -1 << endl;
}
else if (!strcmp(cmd, "front"))
{
if (Q.empty()) cout << -1 << endl;
else cout << Q.front() << endl;
}
else if (!strcmp(cmd, "back"))
{
if (Q.empty()) cout << -1 << endl;
else cout << Q.back() << endl;
}
else if (!strcmp(cmd, "size"))
{
cout << Q.size() << endl;
}
else if (!strcmp(cmd, "empty"))
{
if (Q.empty()) cout << 1<<endl;
else cout << 0<<endl;
}
}
system("pause");
return 0;
}
'Algorithm > Baekjoon' 카테고리의 다른 글
1966 프린터 큐 (0) | 2018.01.16 |
---|---|
1260 - DFS와 BFS (0) | 2018.01.16 |
9012 괄호 (0) | 2018.01.11 |
1874-스택&순열 (0) | 2018.01.11 |
10828-스택기초 (0) | 2018.01.11 |