fork download
  1. #include <vector>
  2. #include <iostream>
  3. #include <algorithm>
  4.  
  5. using namespace std;
  6.  
  7. void solution(vector<int>&v) // Меняем сам вектор
  8. {
  9. if(v.empty()) return;
  10. // Ищем min/max
  11. auto m = minmax_element(v.begin(),v.end());
  12. // Прибавляем **нужное** среднее
  13. int d = abs(*m.first+*m.second)/2; // (abs(*m.first)+abs(*m.second))/2
  14. for_each(v.begin(),v.end(),[d](int&x){ x+= d; });
  15. }
  16.  
  17. int main()
  18. {
  19. vector<int> v{1,2,3,4,5,6,7,8,9};
  20. for(int i: v) cout << i << " "; cout << endl;
  21. solution(v);
  22. for(int i: v) cout << i << " "; cout << endl;
  23. }
  24.  
Success #stdin #stdout 0s 15240KB
stdin
Standard input is empty
stdout
1  2  3  4  5  6  7  8  9  
6  7  8  9  10  11  12  13  14