50求助
  • 板块P9518 queue
  • 楼主small_Dongpo
  • 当前回复3
  • 已保存回复3
  • 发布时间2023/8/13 20:30
  • 上次更新2023/11/3 04:01:39
查看原帖
50求助
741732
small_Dongpo楼主2023/8/13 20:30
#include <iostream>
#include <queue>
#include <cstring>
#include <set>
#define l long long
using namespace std;

queue<string> q;
set<string> s;

int main()
{
    l n;
    string first = "11111111111", second = "11111111111";
    scanf("%lld", &n);
    for (l i = 1; i <= n; ++i)
    {
        while (!q.empty() && s.count("11111111111" + q.front()))
        {
            s.erase("11111111111" + q.front());
            q.pop();
        }
        string str;
        cin >> str;
        if (str == "start")
        {
            if (q.empty() && first == "11111111111")
            {
                printf("Error\n");
                continue;
            }
            if (first != "11111111111")
            {
                q.push(first);
                s.insert(first);
                first = "11111111111";
            }
            if (second != "11111111111")
            {
                q.push(second);
                s.insert(second);
                second = "11111111111";
            }
            first = q.front();
            cout << first << " ";
            s.erase(q.front());
            q.pop();
            while (!q.empty() && s.count("11111111111" + q.front()))
            {
                s.erase("11111111111" + q.front());
                q.pop();
            }
            if (!q.empty())
            {
                second = q.front();
                cout << second;
                s.erase(q.front());
                q.pop();
            }
            printf("\n");
        }
        else if (str == "arrive")
        {
            string x;
            cin >> x;
            if (s.count(x) || first == x || second == x)
            {
                printf("Error\n");
                continue;
            }
            s.insert(x);
            q.push(x);
            printf("OK\n");
        }
        else
        {
            string x;
            cin >> x;
            if (!s.count(x) || first == x || second == x)
            {
                printf("Error\n");
                continue;
            }
            s.erase(x);
            s.insert("11111111111" + x);
            printf("OK\n");
        }
    }
    return 0;
}

set + queue 5050,帮帮蒟蒻QAQ

2023/8/13 20:30
加载中...