#include <stdio.h>
// Body構造体の定義
struct Body {
int id;
int weight;
int height;
};
// swap関数の定義
void swap(struct Body *a, struct Body *b) {
struct Body temp = *a;
*a = *b;
*b = temp;
}
// 構造体配列を身長の逆順に並べ替える関数
void sortByHeight(struct Body a[], int size) {
for (int i = 0; i < size - 1; i++) {
for (int j = i + 1; j < size; j++) {
if (a[i].height < a[j].height) {
swap(&a[i], &a[j]);
}
}
}
}
int main(void) {
// 構造体配列の初期化
struct Body a[] = {
{1, 65, 169},
{2, 73, 170},
{3, 59, 161},
{4, 79, 175},
{5, 55, 168}
};
int size = sizeof(a) / sizeof(a[0]);
// 身長の逆順に並べ替える
sortByHeight(a, size);
// 結果を表示
for (int i = 0; i < size; i++) {
printf("%d %d %d\n", a
[i
].
id, a
[i
].
weight, a
[i
].
height); }
return 0;
}
I2luY2x1ZGUgPHN0ZGlvLmg+CgovLyBCb2R55qeL6YCg5L2T44Gu5a6a576pCnN0cnVjdCBCb2R5IHsKICAgIGludCBpZDsKICAgIGludCB3ZWlnaHQ7CiAgICBpbnQgaGVpZ2h0Owp9OwoKLy8gc3dhcOmWouaVsOOBruWumue+qQp2b2lkIHN3YXAoc3RydWN0IEJvZHkgKmEsIHN0cnVjdCBCb2R5ICpiKSB7CiAgICBzdHJ1Y3QgQm9keSB0ZW1wID0gKmE7CiAgICAqYSA9ICpiOwogICAgKmIgPSB0ZW1wOwp9CgovLyDmp4vpgKDkvZPphY3liJfjgpLouqvplbfjga7pgIbpoIbjgavkuKbjgbnmm7/jgYjjgovplqLmlbAKdm9pZCBzb3J0QnlIZWlnaHQoc3RydWN0IEJvZHkgYVtdLCBpbnQgc2l6ZSkgewogICAgZm9yIChpbnQgaSA9IDA7IGkgPCBzaXplIC0gMTsgaSsrKSB7CiAgICAgICAgZm9yIChpbnQgaiA9IGkgKyAxOyBqIDwgc2l6ZTsgaisrKSB7CiAgICAgICAgICAgIGlmIChhW2ldLmhlaWdodCA8IGFbal0uaGVpZ2h0KSB7CiAgICAgICAg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