Guest User

Untitled

a guest
Feb 20th, 2021
38
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.74 KB | None | 0 0
  1. #include<iostream>
  2. #include<vector>
  3. #include<list>
  4. #include <algorithm>
  5. #include <iterator>
  6. #include <ctime>
  7.  
  8. using namespace std;
  9.  
  10. int main() {
  11. setlocale(LC_ALL, "RUS");
  12. srand(time(NULL));
  13. /*_______________________________________________________________________________________*/
  14. //1 номер
  15. /*_______________________________________________________________________________________*/
  16. cout << "Number 1.\n\n";
  17.  
  18. vector<int>myVector(10); //создаём вектор и задаём ему длину
  19.  
  20. cout << "Initial vector: ";
  21. for (int i = 0; i < 10; i++) { //генерируем числа, не привышающие 1000
  22. myVector[i] = rand() % 10;
  23. cout << myVector[i] << " ";
  24. }
  25.  
  26.  
  27. sort(myVector.begin(), myVector.end()); // сортировка
  28. cout << endl << "Changed vector: ";
  29.  
  30. for (int i = 0; i < 10; i++) {
  31. cout << myVector[i] << " ";
  32. }
  33. cout << endl << endl << "_____________________________";
  34.  
  35. /*_______________________________________________________________________________________*/
  36. //2 номер
  37. /*_______________________________________________________________________________________*/
  38. cout << "\nNumber 2.\n\n";
  39. cout << "Initial vector: ";
  40. list<int>myList;
  41. int n = 10;
  42. for (int i = 0; i < n; i++) { //генерируем числа в список
  43. myList.push_back(rand() % 10);
  44. }
  45. for (auto i = myList.begin(); i != myList.end(); i++) { //выводим
  46. cout << *i << " ";
  47. }
  48.  
  49. auto iter_to_max = max_element(myList.end(), myList.begin());
  50. int index_max = distance(myList.begin(), iter_to_max);
  51.  
  52. list<int>::iterator index_last;
  53. while (true) {
  54. index_max++;
  55.  
  56. for (list<int>::iterator iter = myList.begin(); iter != myList.end(); iter++) //нахождение номера последнего элемента списка
  57. index_last = iter;
  58.  
  59. myList.push_front(*index_last); //перетаскиваем последний элемент в начало последовательности
  60. myList.resize(10);
  61.  
  62. if (index_max == myList.end()) { //если максимальный элемент равен конечному, то заканчиваем на этом
  63. for (list<int>::iterator iter = myList.begin(); iter != myList.end(); iter++)
  64. index_last = iter;
  65.  
  66. myList.push_front(*index_last);
  67. myList.resize(10);
  68. break;
  69. }
  70. }
  71.  
  72.  
  73. cout << endl << "Changed vector: ";
  74. for (auto i = myList.begin(); i != myList.end(); i++) { //вывод изменненого
  75. cout << *i << " ";
  76. }
  77.  
  78. cout << endl << endl << "_____________________________";
  79.  
  80. //resize
  81. /*_______________________________________________________________________________________*/
  82. //3 номер
  83. /*_______________________________________________________________________________________*/
  84. cout << "\nNumber 3.\n\n";
  85.  
  86. vector<int>myVector3(10); //создаём вектор и задаём ему длину
  87.  
  88. cout << "Initial vector: ";
  89. for (int i = 0; i < 10; i++) { //генерируем числа, не привышающие 1000
  90. myVector3[i] = rand() % 10;
  91. cout << myVector3[i] << " ";
  92. }
  93. cout << endl << "Changed vector: ";
  94.  
  95. make_heap(myVector3.begin(), myVector3.end());
  96. for (vector<int>::iterator it = myVector3.begin(); it != myVector3.end(); it++) { //выводим результат
  97. cout << *it << " ";
  98. }
  99. cout << endl << endl << "_____________________________";
  100. /*_______________________________________________________________________________________*/
  101. //4 номер
  102. /*_______________________________________________________________________________________*/
  103.  
  104.  
  105.  
  106.  
  107.  
  108.  
  109. cout << endl << endl;
  110. system("pause");
  111. return 0;
  112. }
  113.  
Advertisement
Add Comment
Please, Sign In to add comment