Ser1ousSAM

Parking

Oct 7th, 2020 (edited)
57
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <iostream>
  2. #include <map>
  3. #include <set>
  4. #include <vector>
  5. using namespace std;
  6. int main() {
  7.     unsigned int m;
  8.     cin >> m;
  9.     map<unsigned int, unsigned int> parking;
  10.     set<unsigned int> free;
  11.     for (unsigned int i = 0; i < m; i++) {
  12.         free.insert(i + 1);
  13.     }
  14.     char t_c;
  15.     unsigned int t_v;
  16.     for (unsigned int i = 0; i < m; i++) {
  17.         cin >> t_c >> t_v;
  18.         if (t_c == '+') {
  19.             unsigned int place = *free.begin();
  20.             parking.insert({t_v, place});
  21.             cout << place << "\n";
  22.             free.erase(place);
  23.         }
  24.         else {
  25.             unsigned int place = parking[t_v];
  26.             free.insert(place);
  27.             parking.erase(t_v);
  28.         }
  29.     }
  30.     return 0;
  31. }
RAW Paste Data