#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_name(Student a[], int n) {
int i, j;
for (i = 0; i < n - 1; i++) {
for (j = n - 1; j > i; j--) {
if (strcmp(a
[j
- 1].
name, a
[j
].
name) > 0) { 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_name(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+CiNpbmNsdWRlIDxzdHJpbmcuaD4KCiNkZWZpbmUgTlVNQkVSIDUKI2RlZmluZSBOQU1FX0xFTiA2NAoKdHlwZWRlZiBzdHJ1Y3QgewogICAgY2hhciBuYW1lW05BTUVfTEVOXTsKICAgIGludCBoZWlnaHQ7CiAgICBmbG9hdCB3ZWlnaHQ7CiAgICBsb25nIG51bWJlcjsKfSBTdHVkZW50OwoKdm9pZCBzd2FwX1N0dWRlbnQoU3R1ZGVudCAqeCwgU3R1ZGVudCAqeSkgewogICAgU3R1ZGVudCB0ZW1wID0gKng7CiAgICAqeCA9ICp5OwogICAgKnkgPSB0ZW1wOwp9Cgp2b2lkIHNvcnRfYnlfbmFtZShTdHVkZW50IGFbXSwgaW50IG4pIHsKICAgIGludCBpLCBqOwogICAgZm9yIChpID0gMDsgaSA8IG4gLSAxOy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