题解 | #【模板】栈#
【模板】栈
https://www.nowcoder.com/practice/104ce248c2f04cfb986b92d0548cccbf
#include <iostream> #include <vector> #include <string> using namespace std; int main() { int n; cin >> n; string temp; int num = 0; int x; int counts[100001]; for (int i = 0; i < n; i++) { cin >> temp; if (temp == "push") { cin >> x; counts[num] = x; num++; } else { if (num > 0) { if (temp == "pop") { cout << counts[num - 1] << endl; num--; } else { cout << counts[num - 1] << endl; } } else { cout << "error" << endl; } } } } // 64 位输出请用 printf("%lld")