求调
  • 板块P9518 queue
  • 楼主cc_lucky
  • 当前回复0
  • 已保存回复0
  • 发布时间2024/7/12 12:30
  • 上次更新2024/7/12 14:19:30
查看原帖
求调
1104948
cc_lucky楼主2024/7/12 12:30
#include<iostream>
#include<queue>
#include<map>
using namespace std;
int n;
string op;
char c;
deque<char>q;
char had1=' ', had2=' ';
map<char, bool>m;
bool start;
int main(){
	ios::sync_with_stdio(0), cin.tie(0), cout.tie(0); 
	cin>>n;
	while(n--){
		cin>>op;
		if(op=="start"){
			start=1;
			if(had1!=' ') q.push_back(had1), had1=' ';
			if(had2!=' ') q.push_back(had2), had2=' ';
			if(q.empty()) cout<<"Error\n";
			else{
				if(q.size()==1) cout<<q.front()<<"\n", had1=q.front(), q.pop_back();
				else{
					if(had1>had2) swap(had1, had2);
					cout<<q.front()<<" ", had1=q.front(), q.pop_front(), cout<<q.front()<<"\n", had1=q.front(), q.pop_front();
				}
			}
		}
		else if(op=="arrive"){
			cin>>c;
			if(m.count(c)) cout<<"Error\n";
			else q.push_back(c), m[c]=1, cout<<"OK\n";
		}
		else{
			cin>>c;
			if(!m.count(c) || had1==c || had2==c) cout<<"Error\n";
			else{
				m.erase(c);
				for(int i=0; i<(int)q.size(); i++){
					q.erase(q.begin()+i);
				}
				cout<<"OK\n";
			}
		}
	}
}

20分

2024/7/12 12:30
加载中...