题解 | #堆栈的使用#
堆栈的使用
http://www.nowcoder.com/practice/e91982a145944ceab6bb9a4a508e0e26
#include<iostream>
#include<cstdio>
#include<stack>
using namespace std;
int main(){
stack<int> Stack;
int n;
char op;
int number;
while(scanf("%d",&n)!=EOF){
for(int i=0;i<n;++i){
scanf("%c",&op);
if(op=='P'){
scanf("%d",&number);
Stack.push(number);
}
else if(op=='O'&&!Stack.empty()){
Stack.pop();
}
else if(op=='A'){
if(!Stack.empty()){
printf("%d\n",Stack.top());
}
else{
cout<<'E'<<endl;
}
}
}
}
return 0;
}
腾讯云智研发成长空间 5050人发布