#include <bits/stdc++.h>
using namespace std;
int main()
{
int n,t;
while(cin >> n >> t)
{
stack<long long>S;
queue<long long>Q;
char st[10];
int flag = 1;
int m = 0;
while(t--)
{
long long num;
cin >> st;
if(strcmp(st,"Add") == 0)
{
cin >> num;
if(m < n)
{
S.push(num);
m++;
}
else
Q.push(num);
}
else if(strcmp(st,"Del") == 0)
{
if(S.empty())
flag = 0;
else
{
S.pop();
m--;
}
}
else if(strcmp(st,"Out") == 0)
{
if(Q.empty())
{
flag = 0;
}
else
Q.pop();
}
while(!Q.empty() && m < n)
{
long long x;
x = Q.front();
Q.pop();
S.push(x);
m++;
}
}
if(flag)
{
while(!S.empty())
{
cout << S.top() << endl;
S.pop();
}
}
else
cout << "Error" << endl;
}
return 0;
}
栈与队列:refresh的停车场
最新推荐文章于 2020-01-13 11:30:57 发布