走运拿到了20分,但还是不会,求助!!!
  • 板块P9518 queue
  • 楼主Aurora09
  • 当前回复0
  • 已保存回复0
  • 发布时间2023/8/19 10:41
  • 上次更新2023/11/3 02:44:46
查看原帖
走运拿到了20分,但还是不会,求助!!!
920271
Aurora09楼主2023/8/19 10:41
using namespace std;
int n;
string s;
char c,x,y;
int a;
deque<char> q;
int main(){
	ios::sync_with_stdio(false);
	cin>>n;
	while(n!=0){
		n--;
		cin>>s;
		if(s=="start"){
			if(!q.empty()){
				if(q.size()==1){
					a=1;
					cout<<q.front()<<endl;
					x=q.front();
					q.pop_front();
					q.push_back(x);
				}	
				else{
					a=2;
					cout<<q.front()<<" ";
					x=q.front();
					q.pop_front();
					cout<<q.front()<<endl;
					y=q.front();
					q.push_back(x);
					q.push_back(y);
				}
			}
			else{
				cout<<"Error"<<endl;
			} 
		}
		else if(s=="arrive"){
			cin>>c;
			bool l=true;
			for(int i=0;i<q.size();i++){
				if(q[i]==c){
					l=0;
					cout<<"Error"<<endl;
				}
			}
			if(l==1){
				cout<<"OK"<<endl;
				q.push_back(c);
			}
		}
		else if(s=="leave"){
			cin>>c;
			bool l=1;
			deque<char>::iterator it=q.begin();
			for(it=q.begin();it!=q.end();it++){
				if(*it==c){
					l=0;
				}
			}
			if(l==0){
				if(a==1&&c!=x){
					cout<<"OK"<<endl;
				}
				else if(a==2&&c!=x&&c!=y){
					cout<<"OK"<<endl;
				}
				else{
					cout<<"Error"<<endl;
				}
			}
			else{
				cout<<"Error"<<endl;
			}
		}
	}
	return 0;
} 
2023/8/19 10:41
加载中...