Advertisement
awsmpshk

Queue #10

Apr 25th, 2020
503
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <fstream>
  2. #include <iostream>
  3. #include <vector>
  4. #include <queue>
  5.  
  6. using namespace std;
  7.  
  8. vector<queue<int>> vec;
  9.  
  10. template <typename T>
  11. void PUSH(int que_num, T value, vector<queue<T>>& vec)
  12. {
  13.   vec[que_num].push(value);
  14. }
  15.  
  16. template <typename T>
  17. void TOP(int que_num, vector<queue<T>>& vec, ofstream& out)
  18. {
  19.    out << vec[que_num].front() << endl;
  20. }
  21.  
  22. template <typename T>
  23. void POP(int que_num, vector<queue<T>>& vec, ofstream& out)
  24. {
  25.   T value = vec[que_num].front();
  26.   vec[que_num].pop();
  27.   out << value << endl;
  28. }
  29.  
  30. int main()
  31. {
  32.   ifstream in("input.txt");
  33.   ofstream out("output.txt");
  34.   int queuesNumber;
  35.   cin >> queuesNumber;
  36.   vector<queue<int>> vec(queuesNumber);
  37.   int value;
  38.   int requestsNumber;
  39.   cin >> requestsNumber;
  40.   string request;
  41.   string funcName;
  42.   int que_num;
  43.  
  44.   for (int i = 0; i < requestsNumber; ++i) {
  45.     cin >> request;
  46.     int i1 = 0, i2;PUSH(100,1)
  47.     i2 = request.find('(') - 1;
  48.     funcName = request.substr(i1, i2);
  49.     if (funcName == "PUSH")
  50.     {
  51.       i1 = i2 + 2;
  52.       i2 = request.find(',') - 1;
  53.       que_num = atoi(request.substr(i1, i2).c_str());
  54.       i1 = i2 + 2;
  55.       i2 = request.find(')') - 1;
  56.       value = atoi(request.substr(i1, i2).c_str());
  57.       PUSH(que_num, value, vec);
  58.     }
  59.     else if (funcName == "TOP")
  60.     {
  61.       i1 = i2 + 2;
  62.       i2 = request.find(')') - 1;
  63.       que_num = atoi(request.substr(i1, i2).c_str());
  64.       TOP(que_num, vec, out);
  65.     }
  66.     else if (funcName == "POP")
  67.     {
  68.       i1 = i2 + 2;
  69.       i2 = request.find(')') - 1;
  70.       que_num = atoi(request.substr(i1, i2).c_str());
  71.       POP(que_num, vec, out);
  72.     }
  73.     i1 = 0;
  74.     i2 = 0;
  75.   }
  76.   in.close();
  77.   out.close();
  78.  
  79.   return 0;
  80. }
Advertisement
RAW Paste Data Copied
Advertisement