题解 | #堆栈的使用# c++ stack
堆栈的使用
https://www.nowcoder.com/practice/e91982a145944ceab6bb9a4a508e0e26
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
char c;
int x;
stack<int> s;
while(cin>>n){
for(int i=0;i<n;i++){
cin>>c;
if(c=='A'){
if(!s.empty()) cout<<s.top()<<endl;
else cout<<'E'<<endl;
}else if(c=='P'){
cin>>x;
s.push(x);
}else{
if(!s.empty()){
s.pop();
}
}
}
}
}
查看19道真题和解析