#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[5] = {
{1, 65, 169},
{2, 73, 170},
{3, 59, 161},
{4, 79, 175},
{5, 55, 168}
};
// 身長を基準に逆順ソート (単純選択ソート)
for (int i = 0; i < 4; i++) {
for (int j = i + 1; j < 5; j++) {
if (a[i].height < a[j].height) { // 身長の逆順
swap(&a[i], &a[j]);
}
}
}
// 結果の表示
for (int i = 0; i < 5; i++) {
printf("%d, %d, %d\n", a
[i
].
id, a
[i
].
weight, a
[i
].
height); }
return 0;
}
I2luY2x1ZGUgPHN0ZGlvLmg+CgovLyDmp4vpgKDkvZPjga7lrprnvqkKdHlwZWRlZiBzdHJ1Y3QgewogICAgaW50IGlkOwogICAgaW50IHdlaWdodDsKICAgIGludCBoZWlnaHQ7Cn0gQm9keTsKCi8vIOODh+ODvOOCv+OCkuWFpeOCjOabv+OBiOOCi3N3YXDplqLmlbAKdm9pZCBzd2FwKEJvZHkgKmEsIEJvZHkgKmIpIHsKICAgIEJvZHkgdGVtcCA9ICphOwogICAgKmEgPSAqYjsKICAgICpiID0gdGVtcDsKfQoKaW50IG1haW4oKSB7CiAgICAvLyDliJ3mnJ/jg4fjg7zjgr8KICAgIEJvZHkgYVs1XSA9IHsKICAgICAgICB7MSwgNjUsIDE2OX0sCiAgICAgICAgezIsIDczLCAxNzB9LAogICAgICAgIHszLCA1OSwgMTYxfSwKICAgICAgICB7NCwgNzksIDE3NX0sCiAgICAgICAgezUsIDU1LCAxNjh9CiAgICB9OwoKICAgIC8vIOi6q+mVt+OCkuWfuua6luOBq+mAhumghuOCveODvOODiCAo5Y2Y57SU6YG45oqe44K944O844OIKQogICAgZm9yIChpbnQgaSA9IDA7IGkgPCA0OyBpKyspIHsKICAgICAgICBmb3IgKGludCBqID0gaSArIDE7IGogPCA1OyBqKyspIHsKICAgICAgICAgICAgaWYgKGFbaV0uaGVpZ2h0IDwgYVtqXS5oZWlnaHQpIHsgLy8g6Lqr6ZW344Gu6YCG6aCGCiAgICAgICAgICAgICAgICBzd2FwKCZhW2ldLCAmYVtqXSk7CiAgICAgICAgICAgIH0KICAgICAgICB9CiAgICB9CgogICAgLy8g57WQ5p6c44Gu6KGo56S6CiAgICBwcmludGYoIklELCDkvZPph40sIOi6q+mVt1xuIik7CiAgICBmb3IgKGludCBpID0gMDsgaSA8IDU7IGkrKykgewogICAgICAgIHByaW50ZigiJWQsICVkLCAlZFxuIiwgYVtpXS5pZCwgYVtpXS53ZWlnaHQsIGFbaV0uaGVpZ2h0KTsKICAgIH0KCiAgICByZXR1cm4gMDsKfQoK
ID, 体重, 身長
4, 79, 175
2, 73, 170
1, 65, 169
5, 55, 168
3, 59, 161