水题,开全局数组,双指针维护即可。
#include<bits/stdc++.h> using i64 = long long; int q[100010]; int l = 0, r = 0; int main() { std::cin.tie(nullptr)->sync_with_stdio(false); int n; std::cin >> n; while (n--) { std::string op; std::cin >> op; if (op == "push") { int x; std::cin >> x; q[r++] = x; } else if (op == "pop") { if (l == r) { std::cout << "error\n"; } else { std::cout << q[l++] << "\n"; } } else { if (l == r) { std::cout << "error\n"; } else { std::cout << q[l] << "\n"; } } } return 0; }