Advertisement
mickypinata

PROG-T1004: Plate

Sep 15th, 2021
897
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.24 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. const int NR = 10;
  5.  
  6. map<int, int> mp;
  7. list<queue<int>> lst;
  8. list<queue<int>>::iterator idx[NR + 1];
  9.  
  10. int main(){
  11.  
  12.     int nRoom, nStu;
  13.     scanf("%d%d", &nRoom, &nStu);
  14.     for(int i = 1; i <= nRoom; ++i){
  15.         idx[i] = lst.end();
  16.     }
  17.     for(int i = 1; i <= nStu; ++i){
  18.         int room, id;
  19.         scanf("%d%d", &room, &id);
  20.         mp[id] = room;
  21.     }
  22.     while(true){
  23.         char cmd;
  24.         scanf(" %c", &cmd);
  25.         if(cmd == 'X'){
  26.             cout << "0\n";
  27.             break;
  28.         } else if(cmd == 'E'){
  29.             int id;
  30.             scanf("%d", &id);
  31.             int room = mp[id];
  32.             if(idx[room] == lst.end()){
  33.                 lst.emplace_back();
  34.                 idx[room] = (--lst.end());
  35.             }
  36.             idx[room] -> push(id);
  37.         } else if(cmd == 'D'){
  38.             if(lst.empty()){
  39.                 cout << "empty\n";
  40.                 continue;
  41.             }
  42.             int id = lst.front().front();
  43.             cout << id << '\n';
  44.             lst.front().pop();
  45.             if(lst.front().empty()){
  46.                 idx[mp[id]] = lst.end();
  47.                 lst.pop_front();
  48.             }
  49.         }
  50.     }
  51.  
  52.     return 0;
  53. }
  54.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement