SDUT OJ refresh的停車場

#include<iostream>
#include<string>
using namespace std;
string a[20010],b[20010];
int main()
{
	int n,m,i,flag;
	string x,y;
	while(cin>>n>>m)
	{
		flag=0;
		int top=0;
		int top1=0;
		int top2=0;
		for(i=0;i<m;i++)
		{
			cin>>x;
			if(x=="Add")
			{
				cin>>y;
				if(top<n)
				{
					a[++top]=y;
				}
				else
				{
					b[++top1]=y;
				}
			}
			if(x=="Del")
			{
				if(top<=0)
				{
					flag=1;
				}
				else if(top2<=top1)
				{
					a[top]=b[++top2];
				}
				else if(top2>top1)
				{
					top--;
				}
			}
			if(x=="Out")
			{
				if(top2>top1)
				{
					flag=1;
				}
				else
				{
					top2++;
				}
			}
		}
			if(top>0 && flag==0)
			{
				while(top>0)
				{
					cout<<a[top--]<<endl;
				}
			}
			else
				cout<<"Error"<<endl;
	}
	return 0;
}


 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章