fork(1) download
  1. #include <vector>
  2. #include <algorithm>
  3. #include <iostream>
  4.  
  5. const int COL = 2;
  6.  
  7. bool compare_vectors(const std::vector<int>& lhs, const std::vector<int>& rhs)
  8. {
  9. return rhs.back() < lhs.back();
  10. }
  11.  
  12. int main()
  13. {
  14. std::vector<std::vector<int>> Arr = {{1, 5}, {2, 8}, {3, 3}};
  15.  
  16. std::sort(Arr.begin(), Arr.end(), compare_vectors);
  17.  
  18.  
  19. // IDEone still has an outdated compiler, no range loops
  20. // for(auto& row: Arr)
  21. // {
  22. // for(auto& n: row)
  23. // std::cout << n << ' ';
  24. // std::cout << '\n';
  25. // }
  26. for(std::size_t row = 0; row < Arr.size(); ++row)
  27. {
  28. for(std::size_t col = 0; col < Arr[row].size(); ++col)
  29. std::cout << Arr[row][col] << ' ';
  30. std::cout << '\n';
  31. }
  32. }
  33.  
Success #stdin #stdout 0s 3064KB
stdin
Standard input is empty
stdout
2 8 
1 5 
3 3