Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- #include <algorithm>
- using namespace std;
- int main() {
- cout << "Введите количество элементов массива: " << endl;
- size_t N;
- cin >> N;
- cout << "Введите массив: ";
- vector<int> array(N);
- for (auto& x : array) cin >> x;
- cout << "Введите минимальный элемент: ";
- int min;
- cin >> min;
- cout << "Введите максимальный элемент: ";
- int max;
- cin >> max;
- // Вычисление количества элементов между максимальным и минимальным
- // элементами. C++
- vector<int>::iterator index_min = std::find(array.begin(), array.end(), min);
- vector<int>::iterator index_max = std::find(array.begin(), array.end(), max);
- cout << "Количество элементов между максимальным и минимальным элементами: ";
- if (index_min <= index_max)
- cout << index_max - index_min - 1;
- else
- cout << index_min - index_max - 1;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement