#include <iostream>
#include <queue>
using namespace std;
int main() {
int n;
cin >> n;
vector<int> q; // 큐 역할
int front = 0; // 앞 인덱스
while(n--) {
string cmd;
cin >> cmd;
if(cmd == "push") {
int x;
cin >> x;
q.push_back(x);
}
else if(cmd == "pop") {
if(front == q.size()) {
cout << -1 << endl;
} else {
cout << q[front] << endl;
front++; // 앞에서 하나 제거
}
}
else if(cmd == "size") {
cout << q.size() - front << endl;
}
else if(cmd == "empty") {
if(front == q.size()) cout << 1 << endl;
else cout << 0 << endl;
}
else if(cmd == "front") {
if(front == q.size()) cout << -1 << endl;
else cout << q[front] << endl;
}
else if(cmd == "back") {
if(front == q.size()) cout << -1 << endl;
else cout << q[q.size() - 1] << endl;
}
}
}
To embed this project on your website, copy the following code and paste it into your website's HTML: