#include <iostream>
#include <algorithm>
template<size_t R, size_t C>
void sort_every_row(int (&a)[R][C])
{
for(size_t r = 0; r < R; ++r)
std::sort(a[r], a[r] + C);
}
template<size_t R, size_t C>
void print_array(int (&a)[R][C])
{
for(size_t r = 0; r < R; ++r)
{
for(size_t c = 0; c < C; ++c)
std::cout << a[r][c] << ' ';
std::cout << '\n';
}
}
int main()
{
int a1[2][4] = {{9, 4, 2, 1},
{3, 5, 6, 2}};
sort_every_row(a1);
print_array(a1);
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8YWxnb3JpdGhtPgoKdGVtcGxhdGU8c2l6ZV90IFIsIHNpemVfdCBDPgp2b2lkIHNvcnRfZXZlcnlfcm93KGludCAoJmEpW1JdW0NdKQp7CiAgICBmb3Ioc2l6ZV90IHIgPSAwOyByIDwgUjsgKytyKQogICAgICAgIHN0ZDo6c29ydChhW3JdLCBhW3JdICsgQyk7Cn0KCnRlbXBsYXRlPHNpemVfdCBSLCBzaXplX3QgQz4Kdm9pZCBwcmludF9hcnJheShpbnQgKCZhKVtSXVtDXSkKewogICAgZm9yKHNpemVfdCByID0gMDsgciA8IFI7ICsrcikKICAgIHsKICAgICAgICBmb3Ioc2l6ZV90IGMgPSAwOyBjIDwgQzsgKytjKQogICAgICAgICAgICBzdGQ6OmNvdXQgPDwgYVtyXVtjXSA8PCAnICc7CiAgICAgICAgc3RkOjpjb3V0IDw8ICdcbic7CiAgICB9Cn0KCgppbnQgbWFpbigpCnsKICAgIGludCBhMVsyXVs0XSA9IHt7OSwgNCwgMiwgMX0sCiAgICAgICAgICAgICAgICAgICAgezMsIDUsIDYsIDJ9fTsKCiAgICBzb3J0X2V2ZXJ5X3JvdyhhMSk7CiAgICBwcmludF9hcnJheShhMSk7Cn0K