Vla_DOS

черга

Jun 28th, 2022
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.42 KB | None | 0 0
  1. #include<iostream>
  2. #include <ctime>
  3. #include <fstream>
  4. #include <string>
  5. #include <list>
  6. #include <queue>
  7. #include <stack>
  8.  
  9.  
  10. using namespace std;
  11.  
  12. void printQueue(queue<int> q)
  13. {
  14.     //printing content of queue
  15.     while (!q.empty()) {
  16.         cout << q.front() << "\t";
  17.         q.pop();
  18.     }
  19.     cout << endl;
  20. }
  21. // Function to reverse the queue
  22. void reverseQueue(queue<int>& Queue)
  23. {
  24.     stack<int> Stack;
  25.     while (!Queue.empty()) {
  26.         Stack.push(Queue.front());
  27.         Queue.pop();
  28.     }
  29.     while (!Stack.empty()) {
  30.         Queue.push(Stack.top());
  31.         Stack.pop();
  32.     }
  33. }
  34.  
  35. int main()
  36. {
  37.     srand((unsigned)time(0));
  38.     setlocale(0, "");
  39.     string path = "input.txt";
  40.     int number = 0;
  41.     list<int> l;
  42.  
  43.     ifstream fin;
  44.     fin.open(path);
  45.     float ch;
  46.     int Count = 0;
  47.     while (fin >> ch)
  48.         Count++;
  49.  
  50.     fin.close();
  51.  
  52.     ifstream file(path);
  53.     for (int i = 0; i < Count; i++) {
  54.         file >> number;
  55.         l.push_back(number);
  56.     }
  57.  
  58.     for (auto i : l)
  59.         cout << i << "\t";
  60.  
  61.     cout << endl;
  62.     fin.close();
  63.     queue<int> q;
  64.     float sum = 0;
  65.     for (auto i : l)
  66.         sum += i;
  67.     float average = sum / Count;
  68.     cout << average << endl;
  69.     for (auto i : l) {
  70.         if (i < average)
  71.             q.push(i);
  72.     }
  73.     reverseQueue(q);
  74.     printQueue(q);
  75.  
  76.     cout << endl;
  77.  
  78.     system("pause");
  79.     return 0;
  80. }
Advertisement
Add Comment
Please, Sign In to add comment