题解 | #堆栈的使用#
堆栈的使用
https://www.nowcoder.com/practice/e91982a145944ceab6bb9a4a508e0e26
#include <cstdio>
#include <stack>
#include <iostream>
using namespace std;
int main(){
int n;
stack<int>use1;
char str;
int num;
while(scanf("%d\n",&n) != EOF){
for (int i =0;i<n;i++){
scanf("%c",&str);
if (str == 'P') {
scanf("%d", &num);
use1.push(num);
}
else if (str == 'O' && use1.size() != 0){
use1.pop();
}
else if (str == 'A'){
if (use1.size() ==0){
printf("E\n");
}
if (use1.size() != 0){
printf("%d\n",use1.top());
}
}
}
}
return 0;
}
深信服公司福利 839人发布