地址:http://acm.hdu.edu.cn/showproblem.php?pid=2093
题意:中文。成绩排序。
mark:看似复杂,其实就是个排序,考察基本功。
代码:
1 # include <stdio.h> 2 # include <string.h> 3 # include <stdlib.h> 4 5 6 typedef struct NODE{ 7 char name[15] ; 8 int num, time ; 9 }NODE ; 10 11 12 NODE stu[1010] ; 13 14 15 int cmp(const void *a, const void *b) 16 { 17 NODE *p = (NODE*)a, *q = (NODE*)b ; 18 if (p->num != q->num) return q->num - p->num ; 19 if (p->time != q->time) return p->time - q->time ; 20 return strcmp(p->name , q->name) ; 21 } 22 23 24 int main () 25 { 26 int i, cnt = 0, n, m, a, b ; 27 char name[15] ; 28 int num, time ; 29 scanf ("%d %d%", &n, &m) ; 30 31 while (~scanf ("%s", name)) 32 { 33 num = time = 0 ; 34 for (i = 0 ; i < n ; i++) 35 { 36 if (scanf ("%d(%d)", &a, &b)==2) 37 time += a + b*m, num++ ; 38 else if (a > 0) 39 time += a, num++ ; 40 } 41 strcpy (stu[cnt].name, name) ; 42 stu[cnt].time = time ; 43 stu[cnt].num = num ; 44 cnt++ ; 45 } 46 qsort(stu, cnt, sizeof(NODE), cmp) ; 47 for (i = 0 ; i < cnt ; i++) 48 { 49 printf ("%-10s %2d %4d\n", stu[i].name, stu[i].num, stu[i].time) ; 50 } 51 return 0 ; 52 }