language: C++11 (gcc-4.7.2)
date: 186 days 13 hours ago
link:
visibility: public
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#include <vector>
#include <algorithm>
#include <iostream>
 
const int COL = 2;
 
bool compare_vectors(const std::vector<int>& lhs, const std::vector<int>& rhs)
{
    return rhs.back() < lhs.back();
}
 
int main()
{
    std::vector<std::vector<int>> Arr = {{1, 5},  {2, 8}, {3, 3}};
 
    std::sort(Arr.begin(), Arr.end(), compare_vectors);
 
 
// IDEone still has an outdated compiler, no range loops
//    for(auto& row: Arr)
//    {
//        for(auto& n: row)
//            std::cout << n << ' ';
//        std::cout << '\n';
//    }
    for(std::size_t row = 0; row < Arr.size(); ++row)
    {
        for(std::size_t col = 0; col < Arr[row].size(); ++col)
            std::cout << Arr[row][col] << ' ';
        std::cout << '\n';
    }
}