40pts 求调QAQ
查看原帖
40pts 求调QAQ
716599
TheCliffSwallow楼主2023/8/12 21:30
#include<iostream>
#include<cstdio>
#include<string>
#include<algorithm>
#include<cstring>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<queue>
#include<map>
#include<set>
#define int long long
using namespace std;
int n;
queue<string>q,g;
set<string>seq,seg;
signed main(){
//	freopen("in.txt","r",stdin);
//	freopen("out.txt","w",stdout);
	cin>>n;
	for(int i=1;i<=n;i++){
		string s;
		cin>>s;
		if(s=="start"){
			int cnt=0;
			while(!g.empty()){
				q.push(g.front());
				seq.insert(g.front());
				seg.erase(g.front());
				g.pop();
			}
			while(!q.empty()){
				if(cnt==2){
					break;
				}
				string tmp=q.front();
				if(seq.count(tmp)==0){
					q.pop();
					continue;
				}
				cnt++;
				cout<<tmp<<' ';
				g.push(tmp);
				seg.insert(tmp);
				seq.erase(tmp);
				q.pop();
			}
			if(!cnt){
				puts("Error");
				continue;
			}
			puts("");
		}else if(s=="arrive"){
			string name;
			cin>>name;
			if(seq.count(name)==1||seg.count(name)==1){
				puts("Error");
			}else{
				q.push(name);
				seq.insert(name);
				puts("OK");
			}
		}else if(s=="leave"){
			string name;
			cin>>name;
			if(seq.count(name)!=1||seg.count(name)==1){
				puts("Error");
			}else{
				seq.erase(name);
				puts("OK");
			}
		}
	}
	return 0;
}
2023/8/12 21:30
加载中...