#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[] = {
{"Sato", 178, 61.2, 21801609900L},
{"Sanaka", 175, 62.5, 21801609911L},
{"Takao", 173, 86.2, 21801609922L},
{"Mike", 165, 72.3, 21801609933L},
{"Masaki", 179, 77.5, 21801609944L},
};
for (i = 0; i < NUMBER; i++) {
printf("%-8s %6d %6.1f %11ld\n", std
[i
].
name, std
[i
].
height, std
[i
].
weight, std
[i
].
number); }
sort_by_name(std, NUMBER);
puts("\n名前の辞書順にソートしました。"); for (i = 0; i < NUMBER; i++) {
printf("%-8s %6d %6.1f %11ld\n", std
[i
].
name, std
[i
].
height, std
[i
].
weight, std
[i
].
number); }
return 0;
}
I2luY2x1ZGU8c3RkaW8uaD4KI2luY2x1ZGU8c3RyaW5nLmg+CiNkZWZpbmUgTlVNQkVSIDUKI2RlZmluZSBOQU1FX0xFTiA2NAoKdHlwZWRlZiBzdHJ1Y3QgewogICAgY2hhciBuYW1lW05BTUVfTEVOXTsKICAgIGludCBoZWlnaHQ7CiAgICBmbG9hdCB3ZWlnaHQ7CiAgICBsb25nIG51bWJlcjsKfSBTdHVkZW50OwoKdm9pZCBzd2FwX1N0dWRlbnQoU3R1ZGVudCAqeCwgU3R1ZGVudCAqeSkgewogICAgU3R1ZGVudCB0ZW1wID0gKng7CiAgICAqeCA9ICp5OwogICAgKnkgPSB0ZW1wOwp9Cgp2b2lkIHNvcnRfYnlfbmFtZShTdHVkZW50IGFbXSwgaW50IG4pIHsKICAgIGludCBpLCBqOwogICAgZm9yIChpID0gMDsgaSA8I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