Posted on 2009-10-12 14:47
Hero 阅读(216)
评论(0) 编辑 收藏 引用 所属分类:
代码如诗--ACM
1 //HLOJ_1017 string 可以用compare()来排序
2
3 #include <iostream>
4 #include <string>
5 using namespace std ;
6
7 const int size = 1100 ;
8
9 int data[size] ;
10
11 struct NODE
12 {
13 string name ;
14 int score ;
15 };
16 struct NODE student[size] ;
17
18 int inn, inm, ing ;
19
20 int cmp( const void *a, const void * b )
21 {
22 struct NODE *c = (struct NODE *)a ;
23 struct NODE *d = (struct NODE *)b ;
24
25 if( c->score != d->score )
26 return d->score - c->score ;
27 else
28 return c->name.compare( d->name ) ;
29 }
30 int main()
31 {
32 while( cin >> inn && inn )
33 {
34 cin >> inm >> ing ;
35 for( int i=1; i<=inm; i++ )
36 {
37 cin >> data[i] ;
38 }
39
40 int nump = 0 ;
41 int ID = 0 ;
42 for( int i=1 ;i<=inn; i++ )
43 {
44 cin >> student[i].name ;
45 student[i].score = 0 ;
46
47 cin >> nump ;
48 for( int j=1; j<=nump; j++ )
49 {
50 cin >> ID ;
51 student[i].score += data[ID] ;
52 }
53 }
54
55 qsort( student+1, inn, sizeof(student[0]), cmp ) ;
56
57 int out = 0 ;
58 for( int i=1; i<=inn; i++ )
59 {
60 if( student[i].score >= ing ) out++ ;
61 }
62 printf( "%d\n", out ) ;
63
64 for( int i=1; i<=inn; i++ )
65 {
66 if( student[i].score < ing ) break ;
67
68 cout << student[i].name << " " << student[i].score << endl ;
69 }
70 }
71 return 0 ;
72 }