20pts下午调了 1个半小时,100多行代码蒟蒻快崩溃了 QwQ
查看原帖
20pts下午调了 1个半小时,100多行代码蒟蒻快崩溃了 QwQ
988735
THE_DARK_FOREST楼主2023/8/12 18:59
#include <cstring>
#include <list>
#include <iostream>
#include <cstdio>
#include <map>
#include <vector>
using namespace std;

list<string> queue;
map<string, bool> dict;
vector<string> cyz;
int n;

void solve()
{
    string op;
    cin >> op;
   if (op[0] == 'a')
    {
        string name;
        cin >> name;
        if (dict[name])
        {
            printf("Error\n");
            return;
        }
        dict[name] = 1;
        queue.push_back(name);
        printf("OK\n");
        return;
    }
    if (op[0] == 's')
    {
         
        if (queue.size() == 0)
        {
            printf("Error\n");
            return;
        }
        
        if (cyz.size() && cyz.at(0) == queue.front())
        {
            queue.push_back(queue.front());
            queue.pop_front();
        }
        
        if (cyz.size() > 1)
        {
            if (cyz.at(1) == queue.front() || cyz.at(0) == queue.front())
            {
                queue.push_back(queue.front());
                queue.pop_front();
            }
        }
        if (queue.size() > 2 && cyz.size())
        {
            auto it = queue.begin();
            it++;
            // cout << "114514 "<< *it << endl;
            string tmp = *it;
            while (*it == cyz[0])
            {
                it = queue.begin();
                it++;
                tmp = *it;
                queue.remove(tmp);
                queue.push_back(tmp);
           }
        }
    #ifndef ONLINE_JUDGE
        cout << "--- ";    
        for (auto it = queue.begin(); it != queue.end(); it++)
        {
            cout << *it << " ";
        }
        cout << endl;
        cout << "###";
        for (string v : cyz)
        {
            cout << v << " ";
        }
        cout << endl;
    #endif

        vector<string> cyztmp;
        if (queue.size() >= 2)
        {
            cout << queue.front() << " ";
            cyztmp.push_back(queue.front());
            queue.push_back(queue.front());
            queue.pop_front();
            queue.push_back(queue.front());
            cout << queue.front() << endl;
            cyztmp.push_back(queue.front());
            queue.pop_front();
        }
        else
        {
            queue.push_back(queue.front());
            cout << queue.front() << endl;
            cyztmp.push_back(queue.front());
            queue.pop_front();
        }
        cyz = cyztmp;
        return;
    }
    if (op[0] == 'l')
    {
        if (queue.size() <= 2)
        {
            cout << "Error\n";
            return;
        }
        string name;
        cin >> name;
        if (cyz.size())
        {
            if (cyz[0] == name)
            {
                cout << "Error\n";
                return;
            }
            if (cyz.size() > 1 && cyz[1] == name)
            {
                cout << "Error\n";
                return;
            }
        }
        
        if (dict[name])
        {
            queue.remove(name);
            dict[name] = 0;
            printf("OK\n");
            return;
        }
        printf("Error\n");
        return;
    }
}

int main()
{
    int T;
    cin >> T;
    while (T--)
    {
        solve();
    }

    /*=== Test the remove function*/
    // list<int> l;
    // for (int i = 1; i <= 4; i++)
    // {
    //     l.push_back(i);
    // }
    // l.remove(4);
    // cout << l.size();
    /*=== The End*/
}
2023/8/12 18:59
加载中...