#include <stdio.h>
// 構造体の定義
typedef struct {
int id;
int weight;
int height;
} 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 n = 5; // 配列の要素数
// 身長の降順でソート
for (int i = 0; i < n - 1; i++) {
for (int j = 0; j < n - 1 - i; j++) {
if (a[j].height < a[j + 1].height) {
swap(&a[j], &a[j + 1]);
}
}
}
// 結果の表示
for (int i = 0; i < n; i++) {
printf("%d, %d, %d\n", a
[i
].
id, a
[i
].
weight, a
[i
].
height); }
return 0;
}
I2luY2x1ZGUgPHN0ZGlvLmg+CgovLyDmp4vpgKDkvZPjga7lrprnvqkKdHlwZWRlZiBzdHJ1Y3QgewogICAgaW50IGlkOwogICAgaW50IHdlaWdodDsKICAgIGludCBoZWlnaHQ7Cn0gQm9keTsKCi8vIHN3YXDplqLmlbAKdm9pZCBzd2FwKEJvZHkgKmEsIEJvZHkgKmIpIHsKICAgIEJvZHkgdGVtcCA9ICphOwogICAgKmEgPSAqYjsKICAgICpiID0gdGVtcDsKfQoKaW50IG1haW4oKSB7CiAgICAvLyDphY3liJfjga7liJ3mnJ/ljJYKICAgIEJvZHkgYVtdID0gewogICAgICAgIHsxLCA2NSwgMTY5fSwKICAgICAgICB7MiwgNzMsIDE3MH0sCiAgICAgICAgezMsIDU5LCAxNjF9LAogICAgICAgIHs0LCA3OSwgMTc1fSwKICAgICAgICB7NSwgNTUsIDE2OH0KICAgIH07CgogICAgaW50IG4gPSA1OyAvLyDphY3liJfjga7opoHntKDmlbAKCiAgICAvLyDouqvplbfjga7pmY3poIbjgafjgr3jg7zjg4gKICAgIGZvciAoaW50IGkgPSAwOyBpIDwgbiAtIDE7IGkrKykgewogICAgICAgIGZvciAoaW50IGogPSAwOyBqIDwgbiAtIDEgLSBpOyBqKyspIHsKICAgICAgICAgICAgaWYgKGFbal0uaGVpZ2h0IDwgYVtqICsgMV0uaGVpZ2h0KSB7CiAgICAgICAgICAgICAgICBzd2FwKCZhW2pdLCAmYVtqICsgMV0pOwogICAgICAgICAgICB9CiAgICAgICAgfQogICAgfQoKICAgIC8vIOe1kOaenOOBruihqOekugogICAgZm9yIChpbnQgaSA9IDA7IGkgPCBuOyBpKyspIHsKICAgICAgICBwcmludGYoIiVkLCAlZCwgJWRcbiIsIGFbaV0uaWQsIGFbaV0ud2VpZ2h0LCBhW2ldLmhlaWdodCk7CiAgICB9CgogICAgcmV0dXJuIDA7Cn0=
4, 79, 175
2, 73, 170
1, 65, 169
5, 55, 168
3, 59, 161