Advertisement
Mancolo

1st task

Oct 6th, 2022
783
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.15 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. #include <algorithm>
  4. using namespace std;
  5.  
  6. int main() {
  7.     cout << "Введите количество элементов массива: " << endl;
  8.     size_t N;
  9.     cin >> N;
  10.  
  11.     cout << "Введите массив: ";
  12.     vector<int> array(N);
  13.     for (auto& x : array) cin >> x;
  14.  
  15.     cout << "Введите минимальный элемент: ";
  16.     int min;
  17.     cin >> min;
  18.  
  19.     cout << "Введите максимальный элемент: ";
  20.     int max;
  21.     cin >> max;
  22.  
  23.     // Вычисление количества элементов между максимальным и минимальным
  24.     // элементами. C++
  25.     vector<int>::iterator index_min = std::find(array.begin(), array.end(), min);
  26.     vector<int>::iterator index_max = std::find(array.begin(), array.end(), max);
  27.  
  28.     cout << "Количество элементов между максимальным и минимальным элементами: ";
  29.     if (index_min <= index_max)
  30.         cout << index_max - index_min - 1;
  31.     else
  32.         cout << index_min - index_max - 1;
  33.  
  34.     return 0;
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement