fork(1) download
  1. #include <vector>
  2. #include <iostream>
  3.  
  4. void replace2(std::vector <int>& a, int n){
  5. for (int i = n-1; i >= 0; --i){
  6. if (a[i] == 2){
  7. a.erase(a.begin() + i);
  8. for(int j = 0; j < 4; ++j){
  9. a.insert(a.begin() + i, 5);
  10. }
  11. }
  12. }
  13. }
  14.  
  15. int main()
  16. {
  17. std::vector<int> a{2, 2, 2};
  18. replace2(a, 3);
  19.  
  20. for(auto item : a )
  21. {
  22. std::cout << item;
  23. }
  24.  
  25. std::cout << std::endl;
  26. }
  27.  
Success #stdin #stdout 0s 15240KB
stdin
Standard input is empty
stdout
555555555555