40求掉!
  • 板块P9518 queue
  • 楼主lijunxi1
  • 当前回复1
  • 已保存回复1
  • 发布时间2023/8/16 20:55
  • 上次更新2023/11/3 03:17:03
查看原帖
40求掉!
696431
lijunxi1楼主2023/8/16 20:55
#include<bits/stdc++.h>
using namespace std;
queue<string>q,yw;
map<string,bool>pd,pdw;
string name,zl,w[5]={"1","1","1"};
int n,c=2;
int main ( )
{
	ios::sync_with_stdio(false);
	cin.tie(0);cout.tie(0);
	cin>>n;
	while(n--)
	{
		cin>>zl;
		if(zl=="start")
		{
			while(!yw.empty())
			{
				q.push(yw.front());
				pdw[yw.front()]=0;
				yw.pop();
			}
			c=2;
			while(c>0&&!q.empty())
			{
				while(q.size()>0&&pd[q.front()]==0)q.pop();
				if(q.empty()||pd[q.front()]==0)break;
				yw.push(q.front());
				w[c]=q.front();
				pdw[q.front()]=1;
				q.pop();
				c--;
			}
			if(c==2)cout<<"Error\n";
			else
			{
				for(int i=2;i>c;i--)cout<<w[i]<<" ";
				cout<<"\n";
			}
		}
		else if(zl=="arrive")
		{
			cin>>name;
			if(pd[name]==1||pdw[name]==1)cout<<"Error\n";
			else
			{
				pd[name]=1;
				cout<<"OK\n";
				q.push(name);
			}
		}
		else if(zl=="leave")
		{
			cin>>name;
			if(pd[name]==0||pdw[name]==1)cout<<"Error\n";
			else
			{
				pd[name]=0;
				pdw[name]=0;
				cout<<"OK\n";
			}
		}
	}
}
2023/8/16 20:55
加载中...