题解 | #【模板】队列#
【模板】队列
https://www.nowcoder.com/practice/afe812c80ad946f4b292a26dd13ba549
#include <iostream> using namespace std; int main() { int n = 0; cin >> n; int res[100000]; int end = 0; int start = 0; for (int i = 0; i < n; i++) { string str; cin >> str; if (str == "push") { cin >> res[end++]; } else if (str == "pop") { if (start < end) { cout << res[start++] << endl; } else { cout << "error" << endl; } } else if (str == "front") { if (start < end) { cout << res[start] << endl; } else { cout << "error" << endl; } } } }