HDU1236 字符串处理

简单

View Code
 1 #include<stdio.h>

 2 #include<string.h>

 3 #include<stdlib.h>

 4 #include<algorithm>

 5 using namespace std;

 6 const int maxn = 1005;

 7 struct node{

 8     char mm[ 24 ];

 9     int num;

10     int ss;

11 }a[ maxn ];

12 int b[ 12 ];

13 bool cmp( node a,node b ){

14     if( a.ss!=b.ss ) return a.ss>b.ss;

15     else if( strcmp(a.mm,b.mm )<0 ) return true;

16     return false;

17 }

18 int main(){

19     int n,m,g;

20     char mm[ 24 ];

21     int num,ss;

22     while( scanf("%d",&n)!=EOF,n ){

23         scanf("%d%d",&m,&g);

24         for( int i=1;i<=m;i++ )

25             scanf("%d",&b[ i ]);

26         int cnt=0;

27         for( int i=1;i<=n;i++ ){

28             scanf("%s",mm);

29             scanf("%d",&num);

30             ss=0;

31             int t;

32             for( int j=0;j<num;j++ ){

33                 scanf("%d",&t);

34                 ss+=b[t];

35             }

36             if( ss>=g ){

37                 strcpy(a[cnt].mm,mm);

38                 a[cnt].num=num;

39                 a[cnt].ss=ss;

40                 cnt++;

41             }

42         }

43         sort( a,a+cnt,cmp );

44         printf("%d\n",cnt);

45         for(int i=0;i<cnt;i++ )

46             printf("%s %d\n",a[i].mm,a[i].ss);

47     }

48     return 0;

49 }

 

你可能感兴趣的:(字符串处理)