#include <stdio.h>
// Body構造体の定義
typedef struct {
int id;
int weight;
int height;
} Body;
// 2つのBody構造体を入れ替えるswap関数
void swap(Body *a, Body *b) {
Body temp = *a;
*a = *b;
*b = temp;
}
int main() {
// 構造体配列の初期化
Body a[] = {
{1, 65, 169},
{2, 73, 170},
{3, 59, 161},
{4, 79, 175},
{5, 55, 168}
};
int size = sizeof(a) / sizeof(a[0]);
// 身長の降順に並べ替え
for (int i = 0; i < size - 1; i++) {
for (int j = 0; j < size - i - 1; j++) {
if (a[j].height < a[j + 1].height) {
swap(&a[j], &a[j + 1]); // データの入れ替え
}
}
}
for (int i = 0; i < size; i++) {
printf("%d\t%d\t%d\n", a
[i
].
id, a
[i
].
weight, a
[i
].
height); }
return 0;
}
I2luY2x1ZGUgPHN0ZGlvLmg+CgovLyBCb2R55qeL6YCg5L2T44Gu5a6a576pCnR5cGVkZWYgc3RydWN0IHsKICAgIGludCBpZDsKICAgIGludCB3ZWlnaHQ7CiAgICBpbnQgaGVpZ2h0Owp9IEJvZHk7CgovLyAy44Gk44GuQm9keeani+mAoOS9k+OCkuWFpeOCjOabv+OBiOOCi3N3YXDplqLmlbAKdm9pZCBzd2FwKEJvZHkgKmEsIEJvZHkgKmIpIHsKICAgIEJvZHkgdGVtcCA9ICphOwogICAgKmEgPSAqYjsKICAgICpiID0gdGVtcDsKfQoKaW50IG1haW4oKSB7CiAgICAvLyDmp4vpgKDkvZPphY3liJfjga7liJ3mnJ/ljJYKICAgIEJvZHkgYVtdID0gewogICAgICAgIHsxLCA2NSwgMTY5fSwKICAgICAgICB7MiwgNzMsIDE3MH0sCiAgICAgICAgezMsIDU5LCAxNjF9LAogICAgICAgIHs0LCA3OSwgMTc1fSwKICAgICAgICB7NSwgNTUsIDE2OH0KICAgIH07CiAgICBpbnQgc2l6ZSA9IHNpemVvZihhKSAvIHNpemVvZihhWzBdKTsKICAgIC8vIOi6q+mVt+OBrumZjemghuOBq+S4puOBueabv+OBiAogICAgZm9yIChpbnQgaSA9IDA7IGkgPCBzaXplIC0gMTsgaSsrKSB7CiAgICAgICAgZm9yIChpbnQgaiA9IDA7IGogPCBzaXplIC0gaSAtIDE7IGorKykgewogICAgICAgICAgICBpZiAoYVtqXS5oZWlnaHQgPCBhW2ogKyAxXS5oZWlnaHQpIHsKICAgICAgICAgICAgICAgIHN3YXAoJmFbal0sICZhW2ogKyAxXSk7IC8vIOODh+ODvOOCv+OBruWFpeOCjOabv+OBiAogICAgICAgICAgICB9CiAgICAgICAgfQogICAgfQoKICAgIGZvciAoaW50IGkgPSAwOyBpIDwgc2l6ZTsgaSsrKSB7CiAgICAgICAgcHJpbnRmKCIlZFx0JWRcdCVkXG4iLCBhW2ldLmlkLCBhW2ldLndlaWdodCwgYVtpXS5oZWlnaHQpOwogICAgfQoKICAgIHJldHVybiAwOwp9