不想讲了,直接上代码
#include<bits/stdc++.h>
using namespace std;
stack<int>s;
int main(){
int n;
char p[1145];
int x;
while (scanf("%d",&n)!=EOF){
while (!s.empty())s.pop();
while (n--){
scanf("%s",p);
if (p[0]=='t'){
if (!s.empty())printf("%d\n",s.top());
else puts("empty");
}
else if (p[1]=='o'){
if (!s.empty())s.pop();
else puts("error");
}
else{
scanf("%d",&x);
s.push(x);
}
}
putchar('\n');
}
return 0;
}
记得点赞