fork download
  1. #include <algorithm>
  2. #include <vector>
  3. #include <iostream>
  4. #include <iterator>
  5. #include <numeric>
  6.  
  7.  
  8. int main()
  9. {
  10. std::vector<int> array(100);
  11. std::iota(array.begin(), array.end(), 0);
  12. std::vector<int> even, odd;
  13. std::partition_copy(array.begin(), array.end(),
  14. std::back_inserter(even),
  15. std::back_inserter(odd),
  16. [](int x){return x%2 == 0;});
  17. std::copy(even.begin(), even.end(), std::ostream_iterator<int>(std::cout, " "));
  18. std::cout << std::endl;
  19. std::copy(odd.begin(), odd.end(), std::ostream_iterator<int>(std::cout, " "));
  20. }
Success #stdin #stdout 0s 3472KB
stdin
Standard input is empty
stdout
0 2 4 6 8 10 12 14 16 18 20 22 24 26 28 30 32 34 36 38 40 42 44 46 48 50 52 54 56 58 60 62 64 66 68 70 72 74 76 78 80 82 84 86 88 90 92 94 96 98 
1 3 5 7 9 11 13 15 17 19 21 23 25 27 29 31 33 35 37 39 41 43 45 47 49 51 53 55 57 59 61 63 65 67 69 71 73 75 77 79 81 83 85 87 89 91 93 95 97 99