#include <stdio.h>
typedef struct {
int id;
int weight;
int height;
} Body;
void swap(Body *a, Body *b) {
Body temp = *a;
*a = *b;
*b = temp;
}
void display(Body arr[], int size) {
for (int i = 0; i < size - 1; i++) {
for (int j = 0; j < size - i - 1; j++) {
if (arr[j].height < arr[j + 1].height) {
swap(&arr[j], &arr[j + 1]);
}
}
}
}
int main() {
Body bodies[] = {
{1, 65, 169},
{2, 73, 170},
{3, 59, 161},
{4, 79, 175},
{5, 55, 168}
};
int size = sizeof(bodies) / sizeof(bodies[0]);
display(bodies, size);
for (int i = 0; i < size; i++) {
printf("%d, %d, %d\n", bodies
[i
].
id, bodies
[i
].
weight, bodies
[i
].
height); }
return 0;
}
I2luY2x1ZGUgPHN0ZGlvLmg+Cgp0eXBlZGVmIHN0cnVjdCB7CiAgICBpbnQgaWQ7CiAgICBpbnQgd2VpZ2h0OwogICAgaW50IGhlaWdodDsKfSBCb2R5OwoKdm9pZCBzd2FwKEJvZHkgKmEsIEJvZHkgKmIpIHsKICAgIEJvZHkgdGVtcCA9ICphOwogICAgKmEgPSAqYjsKICAgICpiID0gdGVtcDsKfQoKdm9pZCBkaXNwbGF5KEJvZHkgYXJyW10sIGludCBzaXplKSB7CiAgICBmb3IgKGludCBpID0gMDsgaSA8IHNpemUgLSAxOyBpKyspIHsKICAgICAgICBmb3IgKGludCBqID0gMDsgaiA8IHNpemUgLSBpIC0gMTsgaisrKSB7CiAgICAgICAgICAgIGlmIChhcnJbal0uaGVpZ2h0IDwgYXJyW2ogKyAxXS5oZWlnaHQpIHsKICAgICAgICAgICAgICAgIHN3YXAoJmFycltqXSwgJmFycltqICsgMV0pOwogICAgICAgICAgICB9CiAgICAgICAgfQogICAgfQp9CgppbnQgbWFpbigpIHsKICAgIEJvZHkgYm9kaWVzW10gPSB7CiAgICAgICAgezEsIDY1LCAxNjl9LAogICAgICAgIHsyLCA3MywgMTcwfSwKICAgICAgICB7MywgNTksIDE2MX0sCiAgICAgICAgezQsIDc5LCAxNzV9LAogICAgICAgIHs1LCA1NSwgMTY4fQogICAgfTsKICAgIGludCBzaXplID0gc2l6ZW9mKGJvZGllcykgLyBzaXplb2YoYm9kaWVzWzBdKTsKICAgIGRpc3BsYXkoYm9kaWVzLCBzaXplKTsKCiAgICBmb3IgKGludCBpID0gMDsgaSA8IHNpemU7IGkrKykgewogICAgICAgIHByaW50ZigiJWQsICVkLCAlZFxuIiwgYm9kaWVzW2ldLmlkLCBib2RpZXNbaV0ud2VpZ2h0LCBib2RpZXNbaV0uaGVpZ2h0KTsKICAgIH0KCiAgICByZXR1cm4gMDsKfQoK
4, 79, 175
2, 73, 170
1, 65, 169
5, 55, 168
3, 59, 161