Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- const int NR = 10;
- map<int, int> mp;
- list<queue<int>> lst;
- list<queue<int>>::iterator idx[NR + 1];
- int main(){
- int nRoom, nStu;
- scanf("%d%d", &nRoom, &nStu);
- for(int i = 1; i <= nRoom; ++i){
- idx[i] = lst.end();
- }
- for(int i = 1; i <= nStu; ++i){
- int room, id;
- scanf("%d%d", &room, &id);
- mp[id] = room;
- }
- while(true){
- char cmd;
- scanf(" %c", &cmd);
- if(cmd == 'X'){
- cout << "0\n";
- break;
- } else if(cmd == 'E'){
- int id;
- scanf("%d", &id);
- int room = mp[id];
- if(idx[room] == lst.end()){
- lst.emplace_back();
- idx[room] = (--lst.end());
- }
- idx[room] -> push(id);
- } else if(cmd == 'D'){
- if(lst.empty()){
- cout << "empty\n";
- continue;
- }
- int id = lst.front().front();
- cout << id << '\n';
- lst.front().pop();
- if(lst.front().empty()){
- idx[mp[id]] = lst.end();
- lst.pop_front();
- }
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement