#include <stdio.h>
#include <stdlib.h>
void crdel(char *s)
{
while (*s != '\n')s++;
*s = '\0';
}
int main(void)
{
char title[100], buf[100], infile[30], outfile[30], name[20];
FILE *fpi, *fpo;
int cnt, *total, *rank, w[5], i, j, number, min, max, tmp;
fpi
= fopen(infile
, "r"); if (fpi == NULL)
{
printf("input file (%s) open error\n", infile
); return 0;
}
printf("output file name = "); fpo
= fopen(outfile
, "w"); if (fpo == NULL)
{
printf("output file (%s) open error\n", outfile
); return 0;
}
for (cnt
= 0; fgets(buf
, 100, fpi
) ; cnt
++); cnt--;
total
= (int *)calloc(sizeof(int) * cnt
, 0); rank
= (int *)calloc(sizeof(int) * cnt
, 0);
for ( i = 0; i < cnt; ++i)
{
sscanf(buf
, "%s %d %d %d %d %d %d %d", name
, &number
, w
, w
+ 1, w
+ 2, w
+ 3, w
+ 4, w
+ 5); for ( j = 0; j < 5; ++j)
total[i] += w[j];
}
min = total[0];
max = total[0];
for ( i = 1; i < cnt; ++i)
{
if (min > total[i])min = total[i];
if (max < total[i])max = total[i];
}
tmp = 1;
for ( i = min; i <= max; ++i)
for ( j = 0; j < cnt; ++j)
if (total[j] == i)
rank[j] = tmp++;
crdel(title);
for ( i = 0; i < cnt; ++i)
{
crdel(buf);
fprintf(fpo
, "%s %d\n", buf
, rank
[i
]); }
return 0;
}
I2luY2x1ZGUgPHN0ZGlvLmg+CiNpbmNsdWRlIDxzdGRsaWIuaD4KCnZvaWQgY3JkZWwoY2hhciAqcykKewogICAgd2hpbGUgKCpzICE9ICdcbicpcysrOwogICAgKnMgPSAnXDAnOwp9CgppbnQgbWFpbih2b2lkKQp7CiAgICBjaGFyIHRpdGxlWzEwMF0sIGJ1ZlsxMDBdLCBpbmZpbGVbMzBdLCBvdXRmaWxlWzMwXSwgbmFtZVsyMF07CiAgICBGSUxFICpmcGksICpmcG87CiAgICBpbnQgY250LCAqdG90YWwsICpyYW5rLCB3WzVdLCBpLCBqLCBudW1iZXIsIG1pbiwgbWF4LCB0bXA7CgogICAgcHJpbnRmKCJpbnB1dCBmaWxlIG5hbWUgPSAiKTsKICAgIHNjYW5mKCIlcyIsIGluZmlsZSk7CiAgICBmcGkgPSBmb3BlbihpbmZpbGUsICJyIik7CiAgICBpZiAoZnBpID09IE5VTEwpCiAgICB7CiAgICAgICAgcHJpbnRmKCJpbnB1dCBmaWxlICglcykgb3BlbiBlcnJvclxuIiwgaW5maWxlKTsKICAgICAgICByZXR1cm4gMDsKICAgIH0KCiAgICBwcmludGYoIm91dHB1dCBmaWxlIG5hbWUgPSAiKTsKICAgIHNjYW5mKCIlcyIsIG91dGZpbGUpOwogICAgZnBvID0gZm9wZW4ob3V0ZmlsZSwgInciKTsKICAgIGlmIChmcG8gPT0gTlVMTCkKICAgIHsKICAgICAgICBwcmludGYoIm91dHB1dCBmaWxlICglcykgb3BlbiBlcnJvclxuIiwgb3V0ZmlsZSk7CiAgICAgICAgcmV0dXJuIDA7CiAgICB9CgogICAgZm9yIChjbnQgPSAwOyBmZ2V0cyhidWYsIDEwMCwgZnBpKSA7IGNudCsrKTsKICAgIGNudC0tOwogICAgdG90YWwgPSAoaW50ICopY2FsbG9jKHNpemVvZihpbnQpICogY250LCAwKTsKICAgIHJhbmsgPSAoaW50ICopY2FsbG9jKHNpemVvZihpbnQpICogY250LCAwKTsKCiAgICByZXdpbmQoZnBpKTsKICAgIGZnZXRzKHRpdGxlLCAxMDAsIGZwaSk7CiAgICBmb3IgKCBpID0gMDsgaSA8IGNudDsgKytpKQogICAgewogICAgICAgIGZnZXRzKGJ1ZiwgMTAwLCBmcGkpOwogICAgICAgIHNzY2FuZihidWYsICIlcyAlZCAlZCAlZCAlZCAlZCAlZCAlZCIsIG5hbWUsICZudW1iZXIsIHcsIHcgKyAxLCB3ICsgMiwgdyArIDMsIHcgKyA0LCB3ICsgNSk7CiAgICAgICAgZm9yICggaiA9IDA7IGogPCA1OyArK2opCiAgICAgICAgICAgIHRvdGFsW2ldICs9IHdbal07CiAgICB9CgogICAgbWluID0gdG90YWxbMF07CiAgICBtYXggPSB0b3RhbFswXTsKICAgIGZvciAoIGkgPSAxOyBpIDwgY250OyArK2kpCiAgICB7CiAgICAgICAgaWYgKG1pbiA+IHRvdGFsW2ldKW1pbiA9IHRvdGFsW2ldOwogICAgICAgIGlmIChtYXggPCB0b3RhbFtpXSltYXggPSB0b3RhbFtpXTsKICAgIH0KCiAgICB0bXAgPSAxOwogICAgZm9yICggaSA9IG1pbjsgaSA8PSBtYXg7ICsraSkKICAgICAgICBmb3IgKCBqID0gMDsgaiA8IGNudDsgKytqKQogICAgICAgICAgICBpZiAodG90YWxbal0gPT0gaSkKICAgICAgICAgICAgICAgIHJhbmtbal0gPSB0bXArKzsKCiAgICByZXdpbmQoZnBpKTsKICAgIGZnZXRzKHRpdGxlLCAxMDAsIGZwaSk7CiAgICBjcmRlbCh0aXRsZSk7CiAgICBmcHJpbnRmKGZwbywgIiVzIHJhbmtcbiIsIHRpdGxlKTsKICAgIGZvciAoIGkgPSAwOyBpIDwgY250OyArK2kpCiAgICB7CiAgICAgICAgZmdldHMoYnVmLCAxMDAsIGZwaSk7CiAgICAgICAgY3JkZWwoYnVmKTsKICAgICAgICBmcHJpbnRmKGZwbywgIiVzICVkXG4iLCBidWYsIHJhbmtbaV0pOwogICAgfQoKICAgIHJldHVybiAwOwp9Cg==