#include <stdio.h>
#include <string.h>
#define NUMBER 5
#define NAME_LEN 64
typedef struct {
char name[NAME_LEN];
int height;
float weight;
long number;
} Student;
void swap_Student(Student *x, Student *y) {
Student temp = *x;
*x = *y;
*y = temp;
}
void sort_by_weight(Student a[], int n) {
int i, j;
for (i = 0; i < n - 1; i++) {
for (j = n - 1; j > i; j--) {
if (a[j - 1].weight < a[j].weight) { // 体重の降順に変更
swap_Student(&a[j - 1], &a[j]);
}
}
}
}
int main(void) {
int i;
Student std[] = {
{"AYASE Eri", 162, 51.9, 1021},
{"WATANABE You", 157, 47.5, 101},
{"NAKASU Kasumi", 155, 44.6, 123},
{"TUSHIMA Yoshiko", 156, 46.7, 713},
{"SONODA Umi", 159, 46.8, 315},
};
for (i = 0; i < NUMBER; i++)
printf("%-14s %6d %6.1f %7ld\n", std
[i
].
name, std
[i
].
height, std
[i
].
weight, std
[i
].
number);
sort_by_weight(std, NUMBER);
for (i = 0; i < NUMBER; i++)
printf("%-14s %6d %6.1f %7ld\n", std
[i
].
name, std
[i
].
height, std
[i
].
weight, std
[i
].
number);
return 0;
}
I2luY2x1ZGUgPHN0ZGlvLmg+CiNpbmNsdWRlIDxzdHJpbmcuaD4KCiNkZWZpbmUgTlVNQkVSIDUKI2RlZmluZSBOQU1FX0xFTiA2NAoKdHlwZWRlZiBzdHJ1Y3QgewogICAgY2hhciBuYW1lW05BTUVfTEVOXTsKICAgIGludCBoZWlnaHQ7CiAgICBmbG9hdCB3ZWlnaHQ7CiAgICBsb25nIG51bWJlcjsKfSBTdHVkZW50OwoKdm9pZCBzd2FwX1N0dWRlbnQoU3R1ZGVudCAqeCwgU3R1ZGVudCAqeSkgewogICAgU3R1ZGVudCB0ZW1wID0gKng7CiAgICAqeCA9ICp5OwogICAgKnkgPSB0ZW1wOwp9Cgp2b2lkIHNvcnRfYnlfd2VpZ2h0KFN0dWRlbnQgYVtdLCBpbnQgbikgewogICAgaW50IGksIGo7CiAgICBmb3IgKGkgPSAwOyBpIDwgbi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