#include <cstdio>
#include <iostream>
#include <stack>
using namespace std;
#ifdef ONLINE_JUDGE
#define FINPUT(file) 0
#define FOUTPUT(file) 0
#else
#define FINPUT(file) freopen(file,"r",stdin)
#define FOUTPUT(file) freopen(file,"w",stdout)
#endif
//一下算法的优点是,就算运算数不是一位的整数也是没关系的
int main()
{
FINPUT("in.txt");
FOUTPUT("out.txt");
int n;
while(cin>>n && n)
{
stack<int> st;
for(int i=0;i<n;i++)
{
char c;
int t;
cin>>c;
if(c==‘P‘)
{
cin>>t;
st.push(t);
}
else if(c==‘O‘)
{
if(!st.empty())
st.pop();
}
else if(c==‘A‘)
{
if(!st.empty())
cout<<st.top()<<endl;
else
cout<<"E"<<endl;
}
}
cout<<endl;
}
return 0;
}原文地址:http://blog.csdn.net/daringpig/article/details/25431815