#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 = sizeof(a) / sizeof(a[0]);
// 身長の降順で並べ替え(バブルソートを使用)
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]);
}
}
}
// 結果を出力
printf("ID, Weight, Height\n"); for (int i = 0; i < n; i++) {
printf("%d, %d, %d\n", a
[i
].
id, a
[i
].
weight, a
[i
].
height); }
return 0;
}
I2luY2x1ZGUgPHN0ZGlvLmg+Cgp0eXBlZGVmIHN0cnVjdCB7CiAgICBpbnQgaWQ7CiAgICBpbnQgd2VpZ2h0OwogICAgaW50IGhlaWdodDsKfSBCb2R5OwoKLy8g44OH44O844K/44KS5YWl44KM5pu/44GI44KLc3dhcOmWouaVsAp2b2lkIHN3YXAoQm9keSAqYSwgQm9keSAqYikgewogICAgQm9keSB0ZW1wID0gKmE7CiAgICAqYSA9ICpiOwogICAgKmIgPSB0ZW1wOwp9CgppbnQgbWFpbigpIHsKICAgIC8vIOWIneacn+ODh+ODvOOCvwogICAgQm9keSBhW10gPSB7CiAgICAgICAgezEsIDY1LCAxNjl9LAogICAgICAgIHsyLCA3MywgMTcwfSwKICAgICAgICB7MywgNTksIDE2MX0sCiAgICAgICAgezQsIDc5LCAxNzV9LAogICAgICAgIHs1LCA1NSwgMTY4fQogICAgfTsKICAgIGludCBuID0gc2l6ZW9mKGEpIC8gc2l6ZW9mKGFbMF0pOwoKICAgIC8vIOi6q+mVt+OBrumZjemghuOBp+S4puOBueabv+OBiO+8iOODkOODluODq+OCveODvOODiOOCkuS9v+eUqO+8iQogICAgZm9yIChpbnQgaSA9IDA7IGkgPCBuIC0gMTsgaSsrKSB7CiAgICAgICAgZm9yIChpbnQgaiA9IDA7IGogPCBuIC0gMSAtIGk7IGorKykgewogICAgICAgICAgICBpZiAoYVtqXS5oZWlnaHQgPCBhW2ogKyAxXS5oZWlnaHQpIHsKICAgICAgICAgICAgICAgIHN3YXAoJmFbal0sICZhW2ogKyAxXSk7CiAgICAgICAgICAgIH0KICAgICAgICB9CiAgICB9CgogICAgLy8g57WQ5p6c44KS5Ye65YqbCiAgICBwcmludGYoIklELCBXZWlnaHQsIEhlaWdodFxuIik7CiAgICBmb3IgKGludCBpID0gMDsgaSA8IG47IGkrKykgewogICAgICAgIHByaW50ZigiJWQsICVkLCAlZFxuIiwgYVtpXS5pZCwgYVtpXS53ZWlnaHQsIGFbaV0uaGVpZ2h0KTsKICAgIH0KCiAgICByZXR1cm4gMDsKfQo=
ID, Weight, Height
4, 79, 175
2, 73, 170
1, 65, 169
5, 55, 168
3, 59, 161