#include<iostream>
using namespace std;
class stack{
private:
int s[1010];
int top_index=-1;
public:
void push(int x){
top_index+=1;
s[top_index]=x;
}
void pop(){
if(top_index>=0){
cout<<s[top_index]<<endl;
top_index-=1;
}
else{
cout<<"error"<<endl;
}
}
void top(){
if(top_index>=0){
cout<<s[top_index]<<endl;
}
else{
cout<<"error"<<endl;
}
}
};
int main(){
stack s;
// 将1入栈
s.push(1);
// 将2入栈
s.push(2);
// 输出栈顶
s.top();
// 输出栈顶,并让栈顶元素出栈
s.pop();
// 输出栈顶
s.top();
return 0;
}