求助!
  • 板块P9518 queue
  • 楼主zjr0330
  • 当前回复1
  • 已保存回复1
  • 发布时间2023/8/12 20:40
  • 上次更新2023/11/3 04:12:32
查看原帖
求助!
746947
zjr0330楼主2023/8/12 20:40

为什么 20 pts?

#include <bits/stdc++.h>
using namespace std;

queue<string> q;
unordered_set<string> playing;
int n;
string sp[500000];

bool ist(string name) {
	int x = q.size();
	bool xp = false;
	for (int i = 0; i < x; i++) {
		sp[i] = q.front();
		if (name == sp[i]) {
			xp = true;
		}
		q.pop();
	}
	for (int i = 0; i < x; i++) {
		q.push(sp[i]);
	}
	return xp;
}

void pd(string name) {
	if (!ist(name)) {
		cout << "Error" << endl;
		return;
	}
	int x = q.size(), er = 0;
	for (int i = 0; i < x; i++) {
		sp[i] = q.front();
		q.pop();
	}
	for (int i = 0; i < x; i++) {
		if (sp[i] == name) {
			er = i;
		}
	}
	for (int i = 0; i < x; i++) {
		if (i != er)
			q.push(sp[i]);
	}
	cout << "OK" << endl;
}

int main() {
	cin >> n;
	string pying1 = "", pying2 = "";
	for (int i = 0; i < n; i++) {
		string event;
		cin >> event;
		if (event == "start") {
			if (pying1 != "") {
				q.push(pying1);
				pying1 = "";
			}
			if (pying2 != "") {
				q.push(pying2);
				pying2 = "";
			}
			if (q.empty()) {
				cout << "Error" << endl;
			} else {
				string p1 = q.front();
				q.pop();
				if (!q.empty()) {
					string p2 = q.front();
					q.pop();
					cout << p1 << " " << p2 << endl;
					pying2 = p2;
				} else {
					cout << p1 << endl;
				}
				pying1 = p1;
//				q.push(p1);
//				if (!q.empty()) {
//					q.push(q.front());
//					q.pop();
//				}
			}
		} else if (event.substr(0, 6) == "arrive") {
			cin >> event;
			string name = event;
			if (name == pying1 || name == pying2) {
				cout << "Error" << endl;
			} else {
				cout << "OK" << endl;
				q.push(name);
			}
		} else if (event.substr(0, 5) == "leave") {
			cin >> event;
			string name = event;
			if (pying1 == name || pying2 == name) {
				cout << "Error" << endl;
			} else {
				pd(event);
			}
		}
	}
	return 0;
}
2023/8/12 20:40
加载中...