Notice
Recent Posts
Recent Comments
Link
Programmer
10845번 큐 본문
#include <iostream>
#include <string>
#include <string.h>
#include <queue>
using namespace std;
void solve() {
int inputNumber;
int pushData;
string command;
queue<int> Queue;
cin >> inputNumber;
for (int i = 0; i < inputNumber; i++) {
cin >> command;
if (!command.compare("push")) {
cin >> pushData;
Queue.push(pushData);
}
else if (!command.compare("front")) {
if (!Queue.size())
cout << "-1" << endl;
else
cout << Queue.front() << endl;
}
else if (!command.compare("back")) {
if (!Queue.size())
cout << "-1" << endl;
else
cout << Queue.back() << endl;
}
else if (!command.compare("size")) {
cout << Queue.size() << endl;
}
else if (!command.compare("empty")) {
cout << Queue.empty() << endl;
}
else if (!command.compare("pop")) {
if (!Queue.size())
cout << "-1" << endl;
else{
cout << Queue.front() << endl;
Queue.pop();
}
}
}
}
int main() {
solve();
return 0;
}
'백준' 카테고리의 다른 글
1158 요세푸스 문제 (0) | 2020.04.13 |
---|---|
1181번 단어 정렬 (0) | 2020.04.11 |
3986번 좋은 단어 (0) | 2020.04.04 |
10828번 스택 (0) | 2020.04.03 |
Comments