题解 | #【模板】栈#
【模板】栈
https://www.nowcoder.com/practice/104ce248c2f04cfb986b92d0548cccbf
#include <bits/stdc++.h>
using namespace std;
int main(){
int n;
int j = -1;
cin >> n;
int w[n];
int i=n;
string s;
for(i=n;i>0;i--) {
cin >> s;
if(s=="push"){
j++;
cin >> w[j];
}
if(s=="pop"){
if(j>=0) {
cout << w[j] << endl;
j--;
}
else cout << "error" << endl;
}
if(s=="top"){
if(j>=0) {
cout << w[j] << endl;
}
else cout << "error" << endl;
}
}
}
