wohyperion

Queue STL

Dec 20th, 2016
132
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.01 KB | None | 0 0
  1. #include <iostream>
  2. #include <cstdlib>
  3. #include <queue>
  4. #include <iterator>
  5.  
  6. using namespace std;
  7.  
  8. float average(queue<int> obj)
  9. {
  10. float sum = 0, i;
  11. for (i = 0; !obj.empty(); ++i)
  12. {
  13. sum += obj.front();
  14. obj.pop();
  15. }
  16. return sum / i;
  17. }
  18.  
  19. int main() {
  20. queue<int> obj;
  21. setlocale(LC_ALL, "russian");
  22. int temp, A, B, size;
  23. cout << "Введите A: ";
  24. cin >> A;
  25. cout << "Введите B: ";
  26. cin >> B;
  27.  
  28. cout << "Вводите числовую последовательность до (ctrl+z): ";
  29. while (cin >> temp) {
  30. obj.push(temp);
  31. }
  32.  
  33. float avg = average(obj);
  34.  
  35. size = obj.size();
  36. int* array = new int[size];
  37. for (int i = 0; i < obj.size(); i++)
  38. {
  39. array[i] = obj.front();
  40. obj.pop();
  41. }
  42.  
  43. for (int i = 0; i < size; i++)
  44. {
  45. if (array[i] < float(A) * avg && array[i] > float(B) * avg)
  46. obj.push(array[i]);
  47. }
  48.  
  49. cout << "Queue: ";
  50. while (!obj.empty()) {
  51. cout << " " << obj.front();
  52. obj.pop();
  53. }
  54. cout << endl;
  55.  
  56. system("pause");
  57. return 0;
  58. }
Advertisement
Add Comment
Please, Sign In to add comment