#include <iostream>
#include <queue>
#include <unordered_set>
#include <string>
using namespace std;

int main() {
    int n;
    cin >> n;
    queue<string> q;
    unordered_set<string> playing;
    for (int i = 0; i < n; i++) {
        string event, name;
        cin >> event;
        if (event == "start") {
            if (q.empty()) {
                cout << "Error" << endl;
            } else {
                int size = min(2, (int)q.size());
                for (int j = 0; j < size; j++) {
                    cout << q.front() << " ";
                    q.pop();
                }
                cout << endl;
            }
        } else if (event == "arrive") {
            cin >> name;
            if (playing.count(name) > 0 || q.size() >= 2) {
                cout << "Error" << endl;
            } else {
                q.push(name);
                cout << "OK" << endl;
            }
        } else if (event == "leave") {
            cin >> name;
            if (playing.count(name) == 0 || q.front() != name) {
                cout << "Error" << endl;
            } else {
                playing.erase(name);
                q.pop();
                cout << "OK" << endl;
            }
        }
        if (!q.empty()) {
            playing.insert(q.front());
        }
    }
    return 0;
}
``
# queue## 题目背景你说的对但是舞萌 DX 是一款后面忘了。## 题目描述补充说明:这里的排队和传统的排队有出入。正在游玩的人为队列的前两位所以正在游玩视为正在排队。机厅里有一台游戏机每次可供最多两人同时游玩。但是来玩的人显然不止两个!这个时候他们就需要排队了而你需要写一个程序维护这个队列并在他人游玩结束后通知接下来上场的人。在整个过程中有以下几种事件可能发生:- start:一局游戏开始

原文地址: https://www.cveoy.top/t/topic/iBxq 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录