#include <bits/stdc++.h>
using namespace std;
int _stack[1010];
int main()
{
int n, m, k, top;
char s[2];
cin >> k;
for(int i = 1; i <= k; i++)
{
top = 0;
cin >> n >> m;
while(m --)
{
scanf("%s", s);
if(s[0] == 'A')
{
if(top!=0)
{
cout << _stack[top-1] << endl;
}
else
{
cout << 'E' << endl;
}
}
else if(s[0] == 'P')
{
int a;
cin >> a;
if(top >= n)
{
cout << 'F' << endl;
}
else
{
_stack[top++] = a;
}
}
else if(s[0] == 'O')
{
if(top == 0)
{
cout << 'E' << endl;
}
else
{
cout << _stack[--top] << endl;
}
}
}
if(i != k)
{
cout << endl;
}
}
return 0;
}
SDUT 3335 数据结构实验之栈八:栈的基本操作
最新推荐文章于 2020-05-13 07:23:36 发布