社区讨论

50 TLE+WA 悬关

P9518queue参与者 1已保存回复 0

讨论操作

快速查看讨论及其快照的属性,并进行相关操作。

当前回复
0 条
当前快照
1 份
快照标识符
@lpdibasy
此快照首次捕获于
2023/11/25 11:43
2 年前
此快照最后确认于
2023/11/25 14:20
2 年前
查看原帖
CPP
#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;
}
模拟求调

回复

0 条回复,欢迎继续交流。

正在加载回复...