Răspuns:
#include <bits/stdc++.h>
using namespace std;
int n, m, i, j, k, aux;
int a[105][105], v[105], x[105];
bool ok;
int
main ()
{
cin >> n >> m;
for (i = 1; i <= n; i++)
for (j = 1; j <= m; j++)
{
cin >> a[i][j];
if (j == 1)
v[i] = a[i][j], x[i] = v[i];
}
do
{
ok = true;
for (i = 1; i < n; i++)
if (v[i] < v[i + 1])
{
aux = v[i];
v[i] = v[i + 1];
v[i + 1] = aux;
ok = false;
}
}
while (!ok);
for (i = 1; i <= n; i++)
{
for (j = 1; j <= m; j++)
for (k = 1; k <= n; k++)
if (v[k] == x[i])
{
cout << a[k][j] << " ";
break;
}
cout << endl;
}
return 0;
}