#include <cstdlib>
#include <iostream>
const int COL = 2;
int compare_rows(const void* lhs, const void* rhs)
{
auto l = static_cast<const int(*)[COL]>(lhs);
auto r = static_cast<const int(*)[COL]>(rhs);
return (*r)[COL-1] - (*l)[COL-1];
}
int main()
{
int Arr[3][COL] = {{1, 5}, {2, 8}, {3, 3}};
std::qsort(Arr, 3, sizeof Arr[0], compare_rows);
// IDEone still has an outdated compiler, no range loops
// for(auto& row: Arr)
// {
// for(auto& n: row)
// std::cout << n << ' ';
// std::cout << '\n';
// }
for(int row = 0; row < 3; ++row)
{
for(int col = 0; col < COL; ++col)
std::cout << Arr[row][col] << ' ';
std::cout << '\n';
}
}
I2luY2x1ZGUgPGNzdGRsaWI+CiNpbmNsdWRlIDxpb3N0cmVhbT4KCmNvbnN0IGludCBDT0wgPSAyOwoKaW50IGNvbXBhcmVfcm93cyhjb25zdCB2b2lkKiBsaHMsIGNvbnN0IHZvaWQqIHJocykKewogICAgYXV0byBsID0gc3RhdGljX2Nhc3Q8Y29uc3QgaW50KCopW0NPTF0+KGxocyk7CiAgICBhdXRvIHIgPSBzdGF0aWNfY2FzdDxjb25zdCBpbnQoKilbQ09MXT4ocmhzKTsKICAgIHJldHVybiAoKnIpW0NPTC0xXSAtICgqbClbQ09MLTFdOwp9CgppbnQgbWFpbigpCnsKICAgIGludCBBcnJbM11bQ09MXSA9IHt7MSwgNX0sIHsyLCA4fSwgezMsIDN9fTsKCiAgICBzdGQ6OnFzb3J0KEFyciwgMywgc2l6ZW9mIEFyclswXSwgY29tcGFyZV9yb3dzKTsKCi8vIElERW9uZSBzdGlsbCBoYXMgYW4gb3V0ZGF0ZWQgY29tcGlsZXIsIG5vIHJhbmdlIGxvb3BzCi8vICAgIGZvcihhdXRvJiByb3c6IEFycikKLy8gICAgewovLyAgICAgICAgZm9yKGF1dG8mIG46IHJvdykKLy8gICAgICAgICAgICBzdGQ6OmNvdXQgPDwgbiA8PCAnICc7Ci8vICAgICAgICBzdGQ6OmNvdXQgPDwgJ1xuJzsKLy8gICAgfQogICAgZm9yKGludCByb3cgPSAwOyByb3cgPCAzOyArK3JvdykKICAgIHsKICAgICAgICBmb3IoaW50IGNvbCA9IDA7IGNvbCA8IENPTDsgKytjb2wpCiAgICAgICAgICAgIHN0ZDo6Y291dCA8PCBBcnJbcm93XVtjb2xdIDw8ICcgJzsKICAgICAgICBzdGQ6OmNvdXQgPDwgJ1xuJzsKICAgIH0KfQo=