C++ 代码
#include<bits/stdc++.h>
using namespace std;
const int N=10010;
int stk[N],tt=0;
int main()
{
int n;
while(cin>>n)
{
if(!n) break;
while(n--)
{
char c; int x;
cin>>c;
if(c=='P')
{
cin>>x;
stk[++tt]=x;
}
else if(c=='O')
{
if(tt) tt--;
}
else if(c=='A')
{
if(tt) cout<<stk[tt]<<endl;
else cout<<"E"<<endl;
}
}
cout<<endl;
}
return 0;
}