Advertisement
Tvor0zhok

Векторы I

Mar 3rd, 2021 (edited)
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.63 KB | None | 0 0
  1. #include <algorithm>
  2. #include <iostream>
  3. #include <numeric>
  4. #include <vector>
  5. using namespace std;
  6.  
  7. int main()
  8. {
  9. int n;
  10. cout << "n = "; cin >> n;
  11.  
  12. vector <int> a;
  13. for (int i = 0; i < n; ++i)
  14. {
  15. int x; cin >> x;
  16.  
  17. a.push_back(x);
  18. }
  19.  
  20. vector <int> :: iterator itmin = min_element(a.begin(), a.end());
  21. vector <int> :: iterator itmax = max_element(a.begin(), a.end());
  22.  
  23. if (itmax > itmin) cout << "Максимальный элемент встречается позже минимального\n";
  24. else cout << "s = " << accumulate(itmax + 1, itmin, 0);
  25.  
  26. return 0;
  27. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement