#include <stdio.h>
typedef struct {
int id;
int weight;
int height;
} Body;
// swap関数: Body型の2つの変数を入れ替える
void swap(Body *a, Body *b) {
Body w = *a;
*a = *b;
*b = w;
}
int main() {
Body a[] = {
{1, 65, 169},
{2, 73, 170},
{3, 59, 161},
{4, 79, 175},
{5, 55, 168}
};
int n = sizeof(a) / sizeof(a[0]);
// 身長を基準に降順にソート
for (int i = 0; i < n - 1; i++) {
for (int j = 0; j < n - i - 1; j++) {
if (a[j].height < a[j + 1].height) {
swap(&a[j], &a[j + 1]);
}
}
}
// 結果の表示
printf("ID\tWeight\tHeight\n"); for (int i = 0; i < n; i++) {
printf("%d\t%d\t%d\n", a
[i
].
id, a
[i
].
weight, a
[i
].
height); }
return 0;
}
I2luY2x1ZGUgPHN0ZGlvLmg+Cgp0eXBlZGVmIHN0cnVjdCB7CiAgICBpbnQgaWQ7CiAgICBpbnQgd2VpZ2h0OwogICAgaW50IGhlaWdodDsKfSBCb2R5OwoKLy8gc3dhcOmWouaVsDogQm9keeWei+OBrjLjgaTjga7lpInmlbDjgpLlhaXjgozmm7/jgYjjgosKdm9pZCBzd2FwKEJvZHkgKmEsIEJvZHkgKmIpIHsKICAgIEJvZHkgdyA9ICphOwogICAgKmEgPSAqYjsKICAgICpiID0gdzsKfQoKaW50IG1haW4oKSB7CiAgICBCb2R5IGFbXSA9IHsKICAgICAgICB7MSwgNjUsIDE2OX0sCiAgICAgICAgezIsIDczLCAxNzB9LAogICAgICAgIHszLCA1OSwgMTYxfSwKICAgICAgICB7NCwgNzksIDE3NX0sCiAgICAgICAgezUsIDU1LCAxNjh9CiAgICB9OwogICAgaW50IG4gPSBzaXplb2YoYSkgLyBzaXplb2YoYVswXSk7CgogICAgLy8g6Lqr6ZW344KS5Z+65rqW44Gr6ZmN6aCG44Gr44K944O844OICiAgICBmb3IgKGludCBpID0gMDsgaSA8IG4gLSAxOyBpKyspIHsKICAgICAgICBmb3IgKGludCBqID0gMDsgaiA8IG4gLSBpIC0gMTsgaisrKSB7CiAgICAgICAgICAgIGlmIChhW2pdLmhlaWdodCA8IGFbaiArIDFdLmhlaWdodCkgewogICAgICAgICAgICAgICAgc3dhcCgmYVtqXSwgJmFbaiArIDFdKTsKICAgICAgICAgICAgfQogICAgICAgIH0KICAgIH0KCiAgICAvLyDntZDmnpzjga7ooajnpLoKICAgIHByaW50ZigiSURcdFdlaWdodFx0SGVpZ2h0XG4iKTsKICAgIGZvciAoaW50IGkgPSAwOyBpIDwgbjsgaSsrKSB7CiAgICAgICAgcHJpbnRmKCIlZFx0JWRcdCVkXG4iLCBhW2ldLmlkLCBhW2ldLndlaWdodCwgYVtpXS5oZWlnaHQpOwogICAgfQoKICAgIHJldHVybiAwOwp9