#include <stdio.h>
#include <stdlib.h>
int** ordena(int **v, int tam) {
int i, j,aux;
int swap[3];
for (i = 0; i < tam-1; i++) {
aux = i;
for (j = (i+1); j < tam; j++) {
if(v[j][1] < v[aux][1]) {
aux = j;
}
}
if (i != aux) {
swap[0] = v[i][0];
swap[1] = v[i][1];
swap[2] = v[i][2];
v[i][0] = v[aux][0];
v[i][1] = v[aux][1];
v[i][2] = v[aux][2];
v[aux][0] = swap[0];
v[aux][1] = swap[1];
v[aux][2] = swap[2];
}
}
return v;
}
int main() {
int **array2d
= malloc(sizeof(*array2d
) * 4); array2d
[0] = malloc(sizeof(*array2d
[0]) * 3); array2d
[1] = malloc(sizeof(*array2d
[0]) * 3); array2d
[2] = malloc(sizeof(*array2d
[0]) * 3); array2d
[3] = malloc(sizeof(*array2d
[0]) * 3);
array2d[0][0] = 2;
array2d[0][1] = 3;
array2d[0][2] = 4;
array2d[1][0] = 3;
array2d[1][1] = 7;
array2d[1][2] = 9;
array2d[2][0] = 1;
array2d[2][1] = 1;
array2d[2][2] = 1;
array2d[3][0] = 5;
array2d[3][1] = 2;
array2d[3][2] = 4;
ordena(array2d, 4);
int i,j;
for (i = 0; i < 4; ++i) {
for (j = 0; j < 3; ++j) {
}
}
return 0;
}
I2luY2x1ZGUgPHN0ZGlvLmg+CiNpbmNsdWRlIDxzdGRsaWIuaD4KCmludCoqIG9yZGVuYShpbnQgKip2LCBpbnQgdGFtKSB7CiAgICBpbnQgaSwgaixhdXg7CiAgICBpbnQgc3dhcFszXTsKICAgIGZvciAoaSA9IDA7IGkgPCB0YW0tMTsgaSsrKSB7CiAgICAgICAgYXV4ID0gaTsKICAgICAgICBmb3IgKGogPSAoaSsxKTsgaiA8IHRhbTsgaisrKSB7CiAgICAgICAgICAgIGlmKHZbal1bMV0gPCB2W2F1eF1bMV0pIHsKICAgICAgICAgICAgICAgIGF1eCA9IGo7CiAgICAgICAgICAgIH0KICAgICAgICB9CiAgICAgICAgaWYgKGkgIT0gYXV4KSB7CiAgICAgICAgICAgIHN3YXBbMF0gPSB2W2ldWzBdOwogICAgICAgICAgICBzd2FwWzFdID0gdltpXVsxXTsKICAgICAgICAgICAgc3dhcFsyXSA9IHZbaV1bMl07CiAgICAgICAgICAgIHZbaV1bMF0gPSB2W2F1eF1bMF07CiAgICAgICAgICAgIHZbaV1bMV0gPSB2W2F1eF1bMV07CiAgICAgICAgICAgIHZbaV1bMl0gPSB2W2F1eF1bMl07CiAgICAgICAgICAgIHZbYXV4XVswXSA9IHN3YXBbMF07CiAgICAgICAgICAgIHZbYXV4XVsxXSA9IHN3YXBbMV07CiAgICAgICAgICAgIHZbYXV4XVsyXSA9IHN3YXBbMl07CiAgICAgICAgfQogICAgfQogICAgcmV0dXJuIHY7Cn0KCmludCBtYWluKCkgewoKICAgIGludCAqKmFycmF5MmQgPSBtYWxsb2Moc2l6ZW9mKCphcnJheTJkKSAqIDQpOwogICAgYXJyYXkyZFswXSA9IG1hbGxvYyhzaXplb2YoKmFycmF5MmRbMF0pICogMyk7CiAgICBhcnJheTJkWzFdID0gbWFsbG9jKHNpemVvZigqYXJyYXkyZFswXSkgKiAzKTsKICAgIGFycmF5MmRbMl0gPSBtYWxsb2Moc2l6ZW9mKCphcnJheTJkWzBdKSAqIDMpOwogICAgYXJyYXkyZFszXSA9IG1hbGxvYyhzaXplb2YoKmFycmF5MmRbMF0pICogMyk7CgogICAgYXJyYXkyZFswXVswXSA9IDI7CiAgICBhcnJheTJkWzBdWzFdID0gMzsKICAgIGFycmF5MmRbMF1bMl0gPSA0OwoKICAgIGFycmF5MmRbMV1bMF0gPSAzOwogICAgYXJyYXkyZFsxXVsxXSA9IDc7CiAgICBhcnJheTJkWzFdWzJdID0gOTsKCiAgICBhcnJheTJkWzJdWzBdID0gMTsKICAgIGFycmF5MmRbMl1bMV0gPSAxOwogICAgYXJyYXkyZFsyXVsyXSA9IDE7CgogICAgYXJyYXkyZFszXVswXSA9IDU7CiAgICBhcnJheTJkWzNdWzFdID0gMjsKICAgIGFycmF5MmRbM11bMl0gPSA0OwoKICAgIG9yZGVuYShhcnJheTJkLCA0KTsKCiAgICBpbnQgaSxqOwogICAgZm9yIChpID0gMDsgaSA8IDQ7ICsraSkgewogICAgICAgIGZvciAoaiA9IDA7IGogPCAzOyArK2opIHsKICAgICAgICAgICAgcHJpbnRmKCIlZCAiLCBhcnJheTJkW2ldW2pdKTsKICAgICAgICB9CgogICAgICAgIHByaW50ZigiXG4iKTsKICAgIH0KCiAgICByZXR1cm4gMDsKfQo=