hdu 1236

地址:http://acm.hdu.edu.cn/showproblem.php?pid=1236

题意:中文名。这种排序题已经无力吐槽了。敲错变量tle了一次- -。

代码:

 1 # include <stdio.h>
 2 # include <stdlib.h>
 3 # include <string.h>
 4 
 5 
 6 typedef struct STU{
 7     char name[25] ;
 8     int scr ;
 9 }STU ;
10 
11 
12 STU stu[1010] ;
13 int scr[15] ;
14 
15 
16 int cmp (const void *a, const void *b)
17 {
18     STU *p = (STU*)a , *q = (STU*)b ;
19     if (p->scr != q->scr) return q->scr - p->scr ;
20     return strcmp(p->name, q->name) ;
21 }
22 
23 
24 int main ()
25 {
26     int n, m, g, i, mm, num, ans ;
27     while (~scanf ("%d", &n),n)
28     {
29         scanf("%d%d", &m, &g) ;
30         ans = 0 ;
31         for (i = 1 ; i <= m ; i++)
32             scanf ("%d", &scr[i]) ;
33         for (i = 0 ; i < n ; i++)
34         {
35             scanf ("%s", stu[i].name) ;
36             stu[i].scr = 0 ;
37             scanf ("%d", &mm) ;
38             while (mm--){
39                 scanf ("%d", &num) ;
40                 stu[i].scr +=  scr[num] ;
41             }
42             if (stu[i].scr >= g) ans++ ;
43         }
44         qsort (stu, n, sizeof(STU), cmp) ;
45         printf ("%d\n", ans) ;
46         for (i = 0 ; i < n ; i++) if (stu[i].scr >= g)
47         {
48             printf ("%s %d\n", stu[i].name, stu[i].scr) ;
49         }
50     }
51     return 0 ;
52 }
posted @ 2012-04-27 06:32  Seraph2012  阅读(267)  评论(0编辑  收藏  举报