백준
백준 소스코드 [C++] 18258 큐 2
Hani_Levenshtein
2020. 9. 7. 23:16
18258번: 큐 2
첫째 줄에 주어지는 명령의 수 N (1 ≤ N ≤ 2,000,000)이 주어진다. 둘째 줄부터 N개의 줄에는 명령이 하나씩 주어진다. 주어지는 정수는 1보다 크거나 같고, 100,000보다 작거나 같다. 문제에 나와있지
www.acmicpc.net
백준 소스코드 [C++] 18258 큐 2
#include <iostream>
#include <utility>
#include <vector>
#include <queue>
#include <string>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n,m;
cin >> n;
queue <int> q;
string xx;
for (int i = 0;i < n;i++) {
cin >> xx;
if (xx == "push") {
cin >> m;
q.push(m);
}
else if (xx == "front") {
if (q.empty() == true) cout << "-1" << '\n';
else {
cout << q.front() << '\n';
}
}
else if (xx == "back") {
if (q.empty() == true) cout << "-1" << '\n';
else {
cout << q.back() << '\n';
}
}
else if (xx == "size") cout << q.size() << '\n';
else if (xx == "empty") cout << q.empty() << '\n';
else if (xx == "pop") {
if (q.empty() == true) cout << "-1" << '\n';
else {
cout << q.front() << '\n';
q.pop();
}
}
}
return 0;
}