fork download
  1. #include <iostream>
  2. #include <cstdlib>
  3. #include <vector>
  4. #include <random>
  5. #include <algorithm>
  6. #include <iterator>
  7.  
  8. bool containsDigit( int value, int digit )
  9. {
  10. do
  11. {
  12. if( value % 10 == digit ) return true;
  13. value /= 10;
  14. } while( value );
  15.  
  16. return false;
  17. }
  18.  
  19. int main(int argc, char *argv[])
  20. {
  21. const int n = 20;
  22. int k = 0;
  23. std::cin >> k;
  24. std::vector<int> v( n );
  25.  
  26. std::random_device rd;
  27. std::mt19937 generator(rd());
  28. std::uniform_int_distribution<> distribution(1,100);
  29.  
  30. std::generate( std::begin(v), std::end(v), [&]() { return distribution(generator);} );
  31.  
  32. std::ostream_iterator<int> oit( std::cout, " " );
  33.  
  34. std::copy( std::begin(v), std::end(v), oit );
  35. std::cout << "\n";
  36.  
  37. auto it = std::begin(v);
  38.  
  39. while( it != std::end(v) )
  40. {
  41. if( containsDigit( *it, 1 ) )
  42. {
  43. it = v.insert( ++it, k );
  44. }
  45. ++it;
  46. }
  47.  
  48. std::copy( std::begin(v), std::end(v), oit );
  49. std::cout << "\n";
  50.  
  51. std::system( "pause" );
  52.  
  53. return 0;
  54. }
Success #stdin #stdout #stderr 0s 3436KB
stdin
13
stdout
18 64 17 85 41 22 70 81 26 38 38 72 17 32 41 72 19 82 31 40 
18 13 64 17 13 85 41 13 22 70 81 13 26 38 38 72 17 13 32 41 13 72 19 13 82 31 13 40 
stderr
sh: pause: not found