#include <bits/stdc++.h>
using namespace std;
typedef int ElemType;
int m;
class Stack{
private:
ElemType *up;
ElemType *base;
ElemType length;
public:
Stack(){
base = new ElemType;
up = base;
length = 0;
}
void push(ElemType x){
*up++ = x;
length++;
}
void pop(){
up--;
length--;
}
ElemType top(){
return *(up - 1);
}
ElemType size(){
return length;
}
bool empty(){
return 0 == length;
}
};
int main()
{
int T,n;
cin >> T;
while(T--)
{
cin >> m >> n;
Stack Q;
while(n--)
{
char s;
int x;
cin >> s;
if(s == 'P')
{
cin >> x;
if(Q.size() >= m)
{
cout << "F" << endl;
}
else
{
Q.push(x);
}
}
else if(s == 'A')
{
if(Q.empty())
{
cout << "E" << endl;
}
else
{
cout << Q.top() << endl;
}
}
else if(s == 'O')
{
if(Q.empty())
{
cout << "E" << endl;
}
else
{
cout << Q.top() << endl;
Q.pop();
}
}
}
if(T)
{
cout << endl;
}
}
return 0;
}
栈的基本操作
最新推荐文章于 2017-12-07 17:13:20 发布