P9518赛时代码40pts求调
  • 板块灌水区
  • 楼主Fwio_
  • 当前回复2
  • 已保存回复2
  • 发布时间2023/8/12 20:37
  • 上次更新2023/11/3 04:12:38
查看原帖
P9518赛时代码40pts求调
965238
Fwio_楼主2023/8/12 20:37

Code:

#include<iostream>
#include<cstring>
#include<algorithm>
#include<unordered_map>
#include<queue>
using namespace std;
int n;
string q[1000010];
int head , tail = -1;
unordered_map<string , bool> now;
unordered_map<string , bool> play;
int k = 0;
int main(){
	cin >> n;
	while(n--){
		string str;
		cin >> str;
		string x;
		if(str == "start"){
			if(head > tail) puts("Error");
			else{
				while(head <= tail){
					if(now[q[head]]){
						if(play[q[head]]){
							play[q[head]] = 0;
							q[++tail] = q[head++];
						}
						else break;
					}
					else head++;
				}
//				for(int i = 0;head + i <= tail && i <= 1 && now[q[head + i]];i++){
//					cout << q[head + i] << " ";
//					play[q[head + i]] = 1;
//				} 
				int p = 0 , cnt = 0;
				while(head + p <= tail && cnt <= 1){
					if(now[q[head + p]]){
						cout << q[head + p] << " ";
						play[q[head + p]] = 1;
						p++; cnt++;
					}
					else p++;
				}
				if(!cnt) puts("Error");
				else cout << endl;
			}
		}
		else if(str == "arrive"){
			cin >> x;
			if(!now[x] && !play[x]){
				cout << "OK" << endl;
				now[x] = 1;
				q[++tail] = x;
			}
			else if(now[x] || play[x]) puts("Error");
		}
		else{
			cin >> x;
			if(!now[x]) puts("Error");
			else if(play[x]) puts("Error");
			else{
				cout << "OK" << endl;
				now[x] = 0;
			} 
		}
	}
	return 0;
}
2023/8/12 20:37
加载中...