Advertisement
Gideer

Untitled

Mar 11th, 2019
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.65 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. #include <string>
  4.  
  5. class Queue {
  6. public:
  7.     Queue(unsigned long long, int);
  8.     void move(unsigned long long);
  9.     void out();
  10.     void move_in_vect(unsigned long long);
  11. private:
  12.     unsigned long long citizens;
  13.     int cases;
  14.     bool test_case;
  15.     std::vector<unsigned long long> list;
  16. };
  17.  
  18. Queue::Queue(unsigned long long citizens, int cases) {
  19.     test_case = cases < citizens;
  20.     this->citizens = citizens;
  21.     this->cases = cases;
  22.     for (long long i = 1; i <= (test_case ? cases : citizens); ++i) list.push_back(i);
  23. }
  24.  
  25. void Queue::move_in_vect(unsigned long long id) {
  26.     int i;
  27.     for (i = 0; i < list.size() && list[i] != id; ++i);
  28.     if (i < list.size() && list[i] == id) {
  29.         list.erase(list.begin() + i);
  30.         list.insert(list.begin(), id);
  31.     }
  32.     else {
  33.         list.insert(list.begin(), id);
  34.     }
  35. }
  36.  
  37. void Queue::move(unsigned long long id) {
  38.     if (test_case) {
  39.         if (id > cases) {
  40.             list.insert(list.begin(), id);
  41.         }
  42.         else {
  43.             move_in_vect(id);
  44.         }
  45.     }
  46.     else {
  47.         move_in_vect(id);
  48.     }
  49. }
  50.  
  51. void Queue::out() {
  52.     std::cout << list[0] << std::endl;
  53.     if (test_case) {
  54.         list.erase(list.begin());
  55.  
  56.     }
  57.     else {
  58.         list.push_back(*list.begin());
  59.         list.erase(list.begin());
  60.     }
  61. }
  62.  
  63. int main() {
  64.     int tests = 0;
  65.     while (true) {
  66.         unsigned long long population; int cases;
  67.         std::cin >> population >> cases;
  68.         if (population == 0 && cases == 0) break;
  69.         Queue queue(population, cases);
  70.         std::cout << "Case " << ++tests << ":\n";
  71.         while (cases--) {
  72.             char MOD;
  73.             std::cin >> MOD;
  74.             if (MOD == 'N') queue.out();
  75.             else {
  76.                 unsigned long long id;
  77.                 std::cin >> id;
  78.                 queue.move_in_vect(id);
  79.             }
  80.         }
  81.     }
  82.     return 0;
  83. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement