#include <stdio.h>
#define SIZEX 25
#define SIZEY 7
// prototype
void mysort();
void disp();
int a[SIZEX + 1][SIZEY] = {0}, cnt = 0, ord[6];
void mysort()
{
int i, j, k, t;
// 科目毎の合計点でsort
for ( i = 1; i < 6; ++i) {
// printf("%d\n", i);
for ( j = i + 1; j < 6; ++j) {
if (a[cnt][i] < a[cnt][j]) {
for (k = 0; k <= cnt; ++k) {
t = a[k][i];
a[k][i] = a[k][j] ;
a[k][j] = t ;
}
t = ord[i];
ord[i] = ord[j];
ord[j] = t;
}
}
}
// 学生毎の合計点でsort
for ( i = 0; i < cnt; ++i) {
for ( j = 0; j < cnt; ++j) {
if (a[i][6] < a[j][6]) {
for ( k = 0; k < 7; ++k) {
t = a[i][k];
a[i][k] = a[j][k] ;
a[j][k] = t;
}
}
}
}
}
void disp()
{
int i, j;
for ( i = 1; i <= 5; ++i)
for ( i = 0; i < cnt; ++i) {
for ( j
= 1; j
< 6; ++j
) printf("%6d", a
[i
][j
]); }
for ( j = 1; j < 6; ++j)
}
int main()
{
FILE *fp;
int i, j, *p = *a;
// データ読込
fp
= fopen("seiseki.dat", "r"); for (p
= *a
; fscanf(fp
, "%d", p
) == 1; ++p
) if (++cnt % 6 == 0)++p;
cnt /= 6;
for ( i = 1; i <= 5; ++i)ord[i] = i;
// 合計計算
for ( i = 0; i < cnt; ++i) {
for ( j = 1; j < 6; ++j) {
a[i][6] += a[i][j];
a[cnt][j] += a[i][j];
a[cnt][6] += a[i][j];
}
}
// 表示
disp();
mysort();
disp();
return 0;
}
I2luY2x1ZGUgPHN0ZGlvLmg+CiNkZWZpbmUgU0laRVggMjUKI2RlZmluZSBTSVpFWSAgNwovLyBwcm90b3R5cGUKdm9pZCBteXNvcnQoKTsKdm9pZCBkaXNwKCk7CgppbnQgYVtTSVpFWCArIDFdW1NJWkVZXSA9IHswfSwgY250ID0gMCwgb3JkWzZdOwoKdm9pZCBteXNvcnQoKQp7CiAgaW50IGksIGosIGssIHQ7CiAgLy8g56eR55uu5q+O44Gu5ZCI6KiI54K544Gnc29ydAogIGZvciAoIGkgPSAxOyBpIDwgNjsgKytpKSB7CiAgICAvLyBwcmludGYoIiVkXG4iLCBpKTsKICAgIGZvciAoIGogPSBpICsgMTsgaiA8IDY7ICsraikgewogICAgICBpZiAoYVtjbnRdW2ldIDwgYVtjbnRdW2pdKSB7CiAgICAgICAgZm9yIChrID0gMDsgayA8PSBjbnQ7ICsraykgewogICAgICAgICAgdCA9IGFba11baV07CiAgICAgICAgICBhW2tdW2ldID0gYVtrXVtqXSA7CiAgICAgICAgICBhW2tdW2pdID0gdCA7CiAgICAgICAgfQogICAgICAgIHQgPSBvcmRbaV07CiAgICAgICAgb3JkW2ldID0gb3JkW2pdOwogICAgICAgIG9yZFtqXSA9IHQ7CiAgICAgIH0KICAgIH0KICB9CiAgLy8g5a2m55Sf5q+O44Gu5ZCI6KiI54K544Gnc29ydAogIGZvciAoIGkgPSAwOyBpIDwgY250OyArK2kpIHsKICAgIGZvciAoIGogPSAwOyBqIDwgY250OyArK2opIHsKICAgICAgaWYgKGFbaV1bNl0gPCBhW2pdWzZdKSB7CiAgICAgICAgZm9yICggayA9IDA7IGsgPCA3OyArK2spIHsKICAgICAgICAgIHQgPSBhW2ldW2tdOwogICAgICAgICAgYVtpXVtrXSA9IGFbal1ba10gOwogICAgICAgICAgYVtqXVtrXSA9IHQ7CiAgICAgICAgfQogICAgICB9CiAgICB9CiAgfQp9Cgp2b2lkIGRpc3AoKQp7CiAgaW50IGksIGo7CiAgcHJpbnRmKCIgIOeVquWPtyAiKTsKICBmb3IgKCBpID0gMTsgaSA8PSA1OyArK2kpCiAgICBwcmludGYoIiAgIOWVjyVkIiwgb3JkW2ldKTsKICBwcmludGYoIiAg5ZCI6KiIXG4iKTsKICBmb3IgKCBpID0gMDsgaSA8IGNudDsgKytpKSB7CiAgICBwcmludGYoIiU2ZCIsIGFbaV1bMF0pOwogICAgZm9yICggaiA9IDE7IGogPCA2OyArK2opIHByaW50ZigiJTZkIiwgYVtpXVtqXSk7CiAgICBwcmludGYoIiU2ZFxuIiwgYVtpXVs2XSk7CiAgfQoKICBwcmludGYoIiAg5ZCI6KiIIik7CiAgZm9yICggaiA9IDE7IGogPCA2OyArK2opCiAgICBwcmludGYoIiU2ZCIsIGFbY250XVtqXSk7CiAgcHJpbnRmKCIlNmRcbiIsIGFbY250XVs2XSk7Cn0KCmludCBtYWluKCkKewogIEZJTEUgKmZwOwogIGludCBpLCBqLCAqcCA9ICphOwoKICAvLyDjg4fjg7zjgr/oqq3ovrwKICBmcCA9IGZvcGVuKCJzZWlzZWtpLmRhdCIsICJyIik7CiAgZm9yIChwID0gKmE7IGZzY2FuZihmcCwgIiVkIiwgcCkgPT0gMTsgKytwKQogICAgaWYgKCsrY250ICUgNiA9PSAwKSsrcDsKICBjbnQgLz0gNjsKICBmb3IgKCBpID0gMTsgaSA8PSA1OyArK2kpb3JkW2ldID0gaTsKCiAgLy8g5ZCI6KiI6KiI566XCiAgZm9yICggaSA9IDA7IGkgPCBjbnQ7ICsraSkgewogICAgZm9yICggaiA9IDE7IGogPCA2OyArK2opIHsKICAgICAgYVtpXVs2XSArPSBhW2ldW2pdOwogICAgICBhW2NudF1bal0gKz0gYVtpXVtqXTsKICAgICAgYVtjbnRdWzZdICs9IGFbaV1bal07CiAgICB9CiAgfQoKICAvLyDooajnpLoKICBwcmludGYoIuaVtOWIl+WJjVxuIik7CiAgZGlzcCgpOwogIG15c29ydCgpOwogIHByaW50Zigi5pW05YiX5b6MXG4iKTsKICBkaXNwKCk7CgogIHJldHVybiAwOwp9Cg==