fork download
  1. #include <iostream>
  2. #include <vector>
  3. #include <iomanip>
  4.  
  5. typedef std::vector<std::vector<int>> matrix;
  6.  
  7. void split( const matrix& src, matrix& zero, matrix& one )
  8. {
  9. //for( auto& v: src )
  10. for( matrix::const_iterator it=src.begin(); it != src.end(); ++it)
  11. {
  12. const std::vector<int>& v = *it;
  13. if( v[v.size()-1] == 0 ) zero.push_back(v);
  14. else one.push_back(v);
  15. }
  16. }
  17.  
  18. void print( const matrix& m )
  19. {
  20. for( auto& v: m )
  21. {
  22. for( auto& e: v )
  23. {
  24. std::cout << std::setw(5) << e;
  25. }
  26. std::cout << std::endl;
  27. }
  28. }
  29.  
  30. int main() {
  31.  
  32. matrix m = {
  33. {1, 2, 3, 4, 5, 1},
  34. {2, 3, 5, 1, 8, 0},
  35. {7, 5, 6, 1, 8, 1},
  36. {3, 6, 8, 1, 2, 0},
  37. {4, 3, 6, 7, 2, 0},
  38. {4, 3, 6, 8, 1, 1},
  39. {4, 3, 6, 8, 1, 0},
  40. {4, 3, 6, 9, 2, 1} };
  41.  
  42. matrix zero;
  43. matrix one;
  44.  
  45. split( m, zero, one );
  46.  
  47. print( zero );
  48.  
  49. std::cout << "--------------" << std::endl;
  50.  
  51. print( one );
  52.  
  53. return 0;
  54. }
Success #stdin #stdout 0s 3032KB
stdin
Standard input is empty
stdout
    2    3    5    1    8    0
    3    6    8    1    2    0
    4    3    6    7    2    0
    4    3    6    8    1    0
--------------
    1    2    3    4    5    1
    7    5    6    1    8    1
    4    3    6    8    1    1
    4    3    6    9    2    1