#include <iostream>
#include <algorithm>
template<typename T, size_t X, size_t Y>
void sort2(T(&arr)[X][Y])
{
T *p = reinterpret_cast<T *>(&arr);
std::sort(p, p + X*Y);
}
int main()
{
int a[3][4] = { { 1,3,2,4 }, { 2,1,5,3 }, { 0,8,2,3 } };
char b[2][5] = { { 'h','e','l','l','o' }, { 'w','o','r','l','d' }};
sort2(a);
for (size_t i = 0; i < 3; ++i)
{
for (size_t j = 0; j < 4; ++j)
std::cout << a[i][j] << " ";
std::cout << std::endl;
}
sort2(b);
for (size_t i = 0; i < 2; ++i)
{
for (size_t j = 0; j < 5; ++j)
std::cout << b[i][j] << " ";
std::cout << std::endl;
}
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8YWxnb3JpdGhtPgoKdGVtcGxhdGU8dHlwZW5hbWUgVCwgc2l6ZV90IFgsIHNpemVfdCBZPgp2b2lkIHNvcnQyKFQoJmFycilbWF1bWV0pCnsKCVQgKnAgPSByZWludGVycHJldF9jYXN0PFQgKj4oJmFycik7CglzdGQ6OnNvcnQocCwgcCArIFgqWSk7Cn0KCmludCBtYWluKCkKewoJaW50IGFbM11bNF0gPSB7IHsgMSwzLDIsNCB9LCB7IDIsMSw1LDMgfSwgeyAwLDgsMiwzIH0gfTsKCWNoYXIgYlsyXVs1XSA9IHsgeyAnaCcsJ2UnLCdsJywnbCcsJ28nIH0sIHsgJ3cnLCdvJywncicsJ2wnLCdkJyB9fTsKCglzb3J0MihhKTsKCglmb3IgKHNpemVfdCBpID0gMDsgaSA8IDM7ICsraSkKCXsKCQlmb3IgKHNpemVfdCBqID0gMDsgaiA8IDQ7ICsraikKCQkJc3RkOjpjb3V0IDw8IGFbaV1bal0gPDwgIiAiOwoJCXN0ZDo6Y291dCA8PCBzdGQ6OmVuZGw7Cgl9CgoJc29ydDIoYik7CgoJZm9yIChzaXplX3QgaSA9IDA7IGkgPCAyOyArK2kpCgl7CgkJZm9yIChzaXplX3QgaiA9IDA7IGogPCA1OyArK2opCgkJCXN0ZDo6Y291dCA8PCBiW2ldW2pdIDw8ICIgIjsKCQlzdGQ6OmNvdXQgPDwgc3RkOjplbmRsOwoJfQp9