70pts求调
  • 板块P9518 queue
  • 楼主hzxphy
  • 当前回复3
  • 已保存回复3
  • 发布时间2023/8/13 10:00
  • 上次更新2023/11/3 04:09:12
查看原帖
70pts求调
742533
hzxphy楼主2023/8/13 10:00
#include <map>
#include <list>
#include <iostream>
#include <algorithm>
//#include <unordered_map>
#define START "start"
#define ARRIVE "arrive"
#define LEAVE "leave"
using namespace std;
list<string> QWQ;
pair<string, string> At;
/*unordered_*/map<string, bool> Mp;

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);
	At.first = At.second = "";
	int n;
	cin >> n;
	while (n--) {
		string op;
		cin >> op;
		if (op == START) {
			pair<string, string> cc = At;
			if (QWQ.size() == 0) {
				cout << "Error\n";
				At.first = At.second = "";
			}
			else {
				if (!(cc.first == ""))QWQ.push_back(cc.first);
				if (!(cc.second == "")) QWQ.push_back(cc.second);
				if (QWQ.size() > 0) {
					At.first = QWQ.front();
					QWQ.pop_front();
					cout << At.first;
				}
				else At.first = "";
				if (QWQ.size() > 0) {
					At.second = QWQ.front();
					QWQ.pop_front();
					cout << " " << At.second;
				}
				else At.second = "";
				cout << '\n';
			}
		}
		else if (op == ARRIVE) {
			string x; cin >> x;
			if (Mp.count(x) || At.first == x || At.second == x)  {
				cout << "Error\n";
			}
			else {
				Mp[x] = true;
				QWQ.push_back(x);
				cout << "OK\n";
			}
		}
		else if (op == LEAVE) {
			string x; cin >> x;
			list<string>::iterator it = find(QWQ.begin(), QWQ.end(), x);
			if (!Mp.count(x) || At.first == x ||
				 At.second == x || it == QWQ.end()) {
				cout << "Error\n";
			}
			else {
				Mp.erase(x);
				QWQ.erase(it);
				cout << "OK\n";
			}
		}
		else {
			cout << "404 NotFound!\n";
		}
	}
	return 0;
}
2023/8/13 10:00
加载中...