#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <math.h>
#include <string>
#include <string.h>
#include <vector>
#include <queue>
#include <stack>
using namespace std;
//1108
int main(){
int n;
char c;
while(scanf("%d",&n)!=EOF&&n!=0){
//getchar();
stack<int> s;
while(!s.empty()) s.pop();
for(int i=0;i<n;i++){
cin>>c;
if(c=='P'){
int t;scanf("%d",&t);
s.push(t);
}else if(c=='A'){
if(!s.empty())
printf("%d\n",s.top());
else
printf("E\n");
}else if(c=='O'){
if(!s.empty()) s.pop();
}
// getchar();
}
printf("\n");
}
return 0;
}
/**************************************************************
Problem: 1108
User: cust123
Language: C++
Result: Accepted
Time:140 ms
Memory:1520 kb
****************************************************************/
题目1108:堆栈的使用
最新推荐文章于 2022-01-17 22:48:31 发布