一开始 40 分 WA 没过,看了题解后还是还无头绪啊(
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
inline int read() {
int x = 0, f = 1; char ch = getchar();
while(ch < '0' || ch > '9') { if(ch == '-') f = -1; ch = getchar(); }
while(ch >= '0' && ch <= '9') { x = (x << 1) + (x << 3) + (ch ^ 48); ch = getchar(); }
return x * f;
}
int n;
map<string, int> place;
//未出现是 0,队伍是 1,机厅是 2
queue<string> q; //队伍
string lstx = "#", lsty = "#";
inline void push(string x) {
if(x == "#") return;
q.push(x);
place[x] = 1;
}
int main() {
speed: std::ios::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
cin >> n;
for(int i = 1; i <= n; i++) {
string s; cin >> s;
if(s == "arrive") {
string x; cin >> x;
if(place[x] == 1 || place[x] == 2) cout << "Error\n";
else {
q.push(x);
place[x] = 1;
cout << "OK\n";
}
}
else if(s == "leave") {
string x; cin >> x;
if(place[x] == 0 || place[x] == 2) cout << "Error\n";
else {
place[x] = 0;
cout << "OK\n";
}
}
else {
push(lstx); push(lsty);
string tmpx = "#", tmpy = "#";
if(q.empty()) { cout << "Error\n"; continue; }
string now = q.front();
while(!q.empty() && place[now] == 0) { q.pop(); now = q.front(); }
if(q.empty() && place[now] == 0) { cout << "Error\n"; continue; }
place[now] = 2; tmpx = now; q.pop();
if(!q.empty()) {
now = q.front();
while(!q.empty() && place[now] == 0) { q.pop(); now = q.front(); }
q.pop();
if(!q.empty() || place[now] != 0) place[now] = 2, tmpy = now;
}
lstx = tmpx, lsty = tmpy;
if(lstx != "#") cout << lstx << " ";
if(lsty != "#") cout << lsty;
cout << "\n";
}
}
return 0;
}