#include <iostream> #include <array> using namespace std; array<int, 100001> a;//--------因为操作数为100000,tail和head最多只可能到100000,可以直接数组表示,如果太大就要用链表模拟了 int head = 0, tail = -1;//--------是个闭区间,当head>tail时表示区间内没有元素 void push(int n){//-------下面就简单了,tail指向队尾,head指向队首 tail++; a[tail] = n; } void pop(){ if (head > tail) puts("error"); else{ cout << a[head] << endl; head++; } } void front(){ if (head > tail) puts("error"); else { cout << a[head] << endl; } } int main() { int n; cin >> n; string s; int x; for (int i = 0; i < n; i++){ cin >> s; if (s == "push"){ cin >> x; push(x); } else if (s == "front") front(); else pop(); } return 0; } // 64 位输出请用 printf("%lld")