#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <string.h>
#define GAKUSEI_MAX 100
#define BUF_SIZE 256
int main()
{
FILE *file;
char buf[BUF_SIZE];
int a[GAKUSEI_MAX][4];
int t[4];
int ninzuu, kamoku, i, j;
do {
} while (GAKUSEI_MAX < ninzuu);
// 読み込み
file
= fopen("seiseki.txt", "rt"); if (file == NULL) {
return 1;
}
fgets(buf
, BUF_SIZE
, file
); // ヘッダ行読み飛ばし for (i = 0; i < ninzuu; i++) {
j
= fscanf(file
, "%d%d%d%d", &a
[i
][0], &a
[i
][1], &a
[i
][2], &a
[i
][3]); if (j != 4) break;
}
ninzuu = i;
do {
} while (kamoku < 1 || 3 < kamoku);
// 並べ替え
for (i = 0; i < ninzuu-1; i++) {
for (j = 0; j < ninzuu-1-i; j++) {
if (a[j][kamoku] > a[j+1][kamoku]) {
memcpy(a
[j
], a
[j
+1], sizeof t
); }
}
}
// 書き込み
file
= fopen("write.txt", "wt"); if (file == NULL) {
return 1;
}
for (i = 0; i < ninzuu; i++) {
fprintf(file
, "%d %d %d %d\n", a
[i
][0], a
[i
][1], a
[i
][2], a
[i
][3]); }
return 0;
}
I2RlZmluZSBfQ1JUX1NFQ1VSRV9OT19XQVJOSU5HUwojaW5jbHVkZSA8c3RkaW8uaD4KI2luY2x1ZGUgPHN0cmluZy5oPgoKI2RlZmluZSBHQUtVU0VJX01BWCAxMDAKI2RlZmluZSBCVUZfU0laRSAyNTYKCmludCBtYWluKCkKewoJRklMRSAqZmlsZTsKCWNoYXIgYnVmW0JVRl9TSVpFXTsKCWludCBhW0dBS1VTRUlfTUFYXVs0XTsKCWludCB0WzRdOwoJaW50IG5pbnp1dSwga2Ftb2t1LCBpLCBqOwoKCXByaW50Zigi5a2m55Sf44Gu5Lq65pWw44KS5YWl5Yqb44GX44Gm44GP44Gg44GV44GE44CCIik7CglkbyB7CgkJc2NhbmYoIiVkIiwgJm5pbnp1dSk7Cgl9IHdoaWxlIChHQUtVU0VJX01BW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