#include <iostream>
#include <cstring>
#include <algorithm>
#include <stack>
using namespace std;
int main(){
int n1,n2,t;
cin>>n1>>n2;
if(n1>n2)
swap(n1,n2);
n1--;
n2--;
int s1[100],top1=-1;
int s2[100],top2=-1;
char c;
while(cin>>c&&c!='T'){
// cin.get();
if(c=='A'){
cin>>t;
// cin.get();
if(top1<n1) {
s1[++top1]=t;
}
else if(top1==n1&&top2==-1){
while(top1!=-1){
s2[++top2]=s1[top1--];
}
s1[++top1]=t;
}
else{
cout<<"ERROR:Full\n";
}
}
else if(c=='D'){
if(top2!=-1){
cout<<s2[top2--]<<endl;
}
else if(top1!=-1){
while(top1!=-1){
s2[++top2]=s1[top1--];
}
cout<<s2[top2--]<<endl;
}
else{
cout<<"ERROR:Empty"<<endl;
}
}
}
return 0;
}
7-22 堆栈模拟队列 (25 分)
最新推荐文章于 2022-02-21 09:50:17 发布