C++98 代码实现游戏机排队系统
#include
using namespace std;
int main() {
int n;
cin >> n;
queue
for (int i = 0; i < n; i++) {
string event;
cin >> event;
if (event == "start") {
if (playing.empty()) {
cout << "Error" << endl;
} else {
stringstream ss;
int count = 0;
while (!q.empty() && count < 2) {
string person = q.front();
q.pop();
playing.erase(person);
ss << person << " ";
count++;
}
cout << ss.str() << endl;
}
} else {
string person;
cin >> person;
if (event == "arrive") {
if (playing.count(person) != 0 || q.size() >= 2) {
cout << "Error" << endl;
} else {
q.push(person);
playing.insert(person);
cout << "OK" << endl;
}
} else if (event == "leave") {
if (playing.count(person) == 0) {
cout << "Error" << endl;
} else {
playing.erase(person);
cout << "OK" << endl;
}
}
}
}
return 0;
}
原文地址: https://www.cveoy.top/t/topic/qinz 著作权归作者所有。请勿转载和采集!