#include <stdio.h>
// Body構造体を定義
typedef struct {
int id; // ID
int weight; // 体重
int height; // 身長
} Body;
// 関数の宣言
void swap(Body data[]);
void display(Body data[]);
int main(void) {
// Body構造体配列を初期化
Body data[] = {
{1, 65, 169},
{2, 73, 170},
{3, 59, 161},
{4, 79, 175},
{5, 55, 168}
};
// データを並び替え
swap(data);
// 結果を表示
display(data);
return 0;
}
// swap関数:データを身長の逆順に並び替える
void swap(Body data[]) {
Body temp;
// 配列の順序を入れ替える
temp = data[0];
data[0] = data[4];
data[4] = temp;
temp = data[1];
data[1] = data[3];
data[3] = temp;
// data[2](中央)はそのままでOK
}
// display関数:データを表示
void display(Body data[]) {
for (int i = 0; i < 5; i++) {
printf("ID: %d, Weight: %d, Height: %d\n", data
[i
].
id, data
[i
].
weight, data
[i
].
height); }
}
I2luY2x1ZGUgPHN0ZGlvLmg+CgovLyBCb2R55qeL6YCg5L2T44KS5a6a576pCnR5cGVkZWYgc3RydWN0IHsKICAgIGludCBpZDsgICAgICAgLy8gSUQKICAgIGludCB3ZWlnaHQ7ICAgLy8g5L2T6YeNCiAgICBpbnQgaGVpZ2h0OyAgIC8vIOi6q+mVtwp9IEJvZHk7CgovLyDplqLmlbDjga7lrqPoqIAKdm9pZCBzd2FwKEJvZHkgZGF0YVtdKTsKdm9pZCBkaXNwbGF5KEJvZHkgZGF0YVtdKTsKCmludCBtYWluKHZvaWQpIHsKICAgIC8vIEJvZHnmp4vpgKDkvZPphY3liJfjgpLliJ3mnJ/ljJYKICAgIEJvZHkgZGF0YVtdID0gewogICAgICAgIHsxLCA2NSwgMTY5fSwKICAgICAgICB7MiwgNzMsIDE3MH0sCiAgICAgICAgezMsIDU5LCAxNjF9LAogICAgICAgIHs0LCA3OSwgMTc1fSwKICAgICAgICB7NSwgNTUsIDE2OH0KICAgIH07CiAgICAKICAgIC8vIOODh+ODvOOCv+OCkuS4puOBs+abv+OBiAogICAgc3dhcChkYXRhKTsKICAgIAogICAgLy8g57WQ5p6c44KS6KGo56S6CiAgICBkaXNwbGF5KGRhdGEpOwoKICAgIHJldHVybiAwOwp9CgovLyBzd2Fw6Zai5pWw77ya44OH44O844K/44KS6Lqr6ZW344Gu6YCG6aCG44Gr5Lim44Gz5pu/44GI44KLCnZvaWQgc3dhcChCb2R5IGRhdGFbXSkgewogICAgQm9keSB0ZW1wOwoKICAgIC8vIOmFjeWIl+OBrumghuW6j+OCkuWFpeOCjOabv+OBiOOCiwogICAgdGVtcCA9IGRhdGFbMF07CiAgICBkYXRhWzBdID0gZGF0YVs0XTsKICAgIGRhdGFbNF0gPSB0ZW1wOwoKICAgIHRlbXAgPSBkYXRhWzFdOwogICAgZGF0YVsxXSA9IGRhdGFbM107CiAgICBkYXRhWzNdID0gdGVtcDsKCiAgICAvLyBkYXRhWzJd77yI5Lit5aSu77yJ44Gv44Gd44Gu44G+44G+44GnT0sKfQoKLy8gZGlzcGxheemWouaVsO+8muODh+ODvOOCv+OCkuihqOekugp2b2lkIGRpc3BsYXkoQm9keSBkYXRhW10pIHsKICAgIGZvciAoaW50IGkgPSAwOyBpIDwgNTsgaSsrKSB7CiAgICAgICAgcHJpbnRmKCJJRDogJWQsIFdlaWdodDogJWQsIEhlaWdodDogJWRcbiIsIGRhdGFbaV0uaWQsIGRhdGFbaV0ud2VpZ2h0LCBkYXRhW2ldLmhlaWdodCk7CiAgICB9Cn0=
ID: 5, Weight: 55, Height: 168
ID: 4, Weight: 79, Height: 175
ID: 3, Weight: 59, Height: 161
ID: 2, Weight: 73, Height: 170
ID: 1, Weight: 65, Height: 169