50 TLE+WA 悬关
  • 板块P9518 queue
  • 楼主sfqxx1
  • 当前回复0
  • 已保存回复0
  • 发布时间2023/11/25 11:43
  • 上次更新2023/11/25 14:20:31
查看原帖
50 TLE+WA 悬关
934014
sfqxx1楼主2023/11/25 11:43
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main() {
    int a;
    cin >> a;
    vector<string> queue;
    vector<string> playing;
    for (int i = 0; i < a; i++) {
        string command;
        cin >> command;
        if (command == "start") {
            if (queue.empty()) {
                cout << "Error" << endl;
            } else {
                if (!playing.empty()) {
                    queue.insert(queue.end(), playing.begin(), playing.end());
                }
                playing.clear();
                playing.push_back(queue.front());
                queue.erase(queue.begin());
                if (!queue.empty()) {
                    playing.push_back(queue.front());
                    queue.erase(queue.begin());
                }
                for (const auto &player : playing) {
                    cout << player << " ";
                }
                cout << endl;
            }
        } else if (command == "arrive") {
            string name;
            cin >> name;
            if (find(queue.begin(), queue.end(), name) == queue.end() && find(playing.begin(), playing.end(), name) == playing.end()) {
                queue.push_back(name);
                cout << "OK" << endl;
            } else {
                cout << "Error" << endl;
            }
        } else if (command == "leave") {
            string name;
            cin >> name;
            auto it = find(queue.begin(), queue.end(), name);
            if (it != queue.end() && find(playing.begin(), playing.end(), name) == playing.end()) {
                queue.erase(it);
                cout << "OK" << endl;
            } else {
                cout << "Error" << endl;
            }
        }
    }
    return 0;
}

模拟求调

2023/11/25 11:43
加载中...