whhy CE???
  • 板块学术版
  • 楼主封禁用户
  • 当前回复22
  • 已保存回复22
  • 发布时间2024/7/23 12:27
  • 上次更新2024/7/23 14:16:15
查看原帖
whhy CE???
1198296
封禁用户楼主2024/7/23 12:27
#include<bits/stdc++.h>
using namespace std;
#define endl '\n'
deque<pair<string,bool> > dq;//队列
void change(){
	while(dq.size()&&dq.front().second==0) dq.pop_front();//把已经删除过的人去掉
    if(!dq.size()) return ;
	dq.push_back(dq.front());
	dq.pop_front();
}
signed main(){
	int n,qwq=0;//qwq->上一次在机厅玩DX的人数
	string s,x;
	cin>>n;
	while(n--){
		cin>>s;
		if(s=="start"){
			while(dq.size()&&dq.front().second==0) dq.pop_front();//把已经删除过的人去掉
			if(dq.size()) for(int i=1;i<=qwq;++i) change();//把正在玩的人放到队尾
			while(dq.size()&&dq.front().second==0) dq.pop_front();//把已经删除过的人去掉
			if(dq.empty()) cout<<"Error"<<endl;//队列为空
			else if(dq.size()==1){//一个人
				cout<<dq.front().first<<endl;
				qwq=1;
			}
			else{//大于等于两个人
				auto fir=dq.front();
				cout<<dq.front().first<<' ';
				dq.pop_front();
				while(dq.size()&&dq.front().second==0) dq.pop_front();
				if(dq.size()){
					cout<<dq.front().first<<endl;
					qwq=2;
				}
				else{
					cout<<endl;
					qwq=1;
				}
				dq.push_front(fir);
			}
		}
		else if(s=="arrive"){
			cin>>x;
			bool f=0;
			for(auto i:dq){
				if(i.first==x&&i.second){
					f=1;
					cout<<"Error"<<endl;
					break;
				}
			}
			//if(st.find(x)!=st.end()) cout<<"Error"<<endl;//队列中已经有这个人
			//队列中没有这个人
			if(f!=1) continue;
			dq.push_back({x,1});//插入队尾
			cout<<"OK"<<endl;
			
		}
		else{
			cin>>x;
			while(dq.size()&&dq.front().second==0) dq.pop_front();//把已经删除过的人去掉
			deque<pair<string,bool> >::iterator it=find(dq.begin(),dq.end(),make_pair(x,1));
			if(dq.empty()||it==dq.end()) cout<<"Error"<<endl;
			else if(qwq>=1&&dq.front().first==x) cout<<"Error"<<endl;//队列中没有这个人\这个人在玩DX
			//这个人在玩DX:队列中“所谓”的第二个人没被删除\队列中“所谓”的第二个人被删除
			else if(qwq==2){
				auto fir=dq.front();
				dq.pop_front();
				while(dq.size()&&dq.front().second==0) dq.pop_front();//把已经删除过的人去掉
				if(dq.front().first==x) cout<<"Error"<<endl;
				else{
					//删掉这个人
					for(auto i:dq){
						if(i.first==x) i.second=0;
					}
					cout<<"OK"<<endl;
				}
				dq.push_front(fir);
			}
			else{
				//删掉这个人
				for(auto i:dq){
					if(i.first==x) i.second=0;
				}
				cout<<"OK"<<endl;
			}
		}
	}
	return 0;
}
2024/7/23 12:27
加载中...