石山代码求助
  • 板块P9518 queue
  • 楼主Zmk2009
  • 当前回复0
  • 已保存回复0
  • 发布时间2023/11/16 20:05
  • 上次更新2023/11/16 21:16:04
查看原帖
石山代码求助
625671
Zmk2009楼主2023/11/16 20:05
#include <bits/stdc++.h>
using namespace std;
#define puter {cout<<"Error"<<endl;continue;}
#define ok {cout<<"OK"<<endl;continue;}
queue<string> q;
set<string> st;
map <string,bool> vis;
string playa = "" , playb = "";
string take_out(){
    string s;
    if (st.empty()) return "";
    while (1){
        s = q.front();q.pop();
        if (vis[s]) break;
    }
    return s;
}
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int n;
    cin >> n;
    for (int i = 1;i <= n ;i++){
        string s;
        cin >> s;
        string x;
        if (s == "start"){
            if (st.empty()) puter;
            if (playa != "") q.push(playa);
            if (playb != "") q.push(playb);
            string a = take_out() ;
            playa = a;
            string b = "";
            if (st.size() > 1) b = take_out();
            playb = b;
            cout << a << ' ' << b << endl;
        }
        else if (s == "arrive"){
            cin >> x;
            if (vis[x]) puter;
            st.insert(x);
            q.push(x);
            vis[x] = 1;
            ok;
        }
        else {
            cin >> x;
            if (!vis[x]) puter;
            if (x == playa || x == playb) puter;
            st.erase(x);
            vis[x] = 0;
            ok;
        }
    }
    return 0;
}

提交记录

2023/11/16 20:05
加载中...