杭电acm1236

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

这题在于做题时间的比较,中间要分类去判断出高低,关键在于冒泡排序会超时,要用比较高效的排序,这里用的快排

View Code
 1 #include <stdio.h>
 2 #include <string.h>
 3 #include <stdlib.h>
 4 typedef struct
 5 {
 6  char nam[30];
 7  int score;
 8 }stud;
 9 
10 stud stu[1001];
11 
12 int cmp(const void * a,const void * b)
13 {
14  stud *c = (stud *)a;
15  stud *d = (stud *)b;
16  if(c->score != d->score) return d->score - c->score;
17  else return strcmp(c->nam,d->nam);
18 
19 }
20 
21 int main()
22 {
23  int m,n,g,i,j,fen[11],sum,t,x,q;
24  while(scanf("%d",&n),n)
25  {
26   q = 0;
27   scanf("%d%d",&m,&g);
28   for(i = 0; i <m; i++)
29    scanf("%d",&fen[i]);
30   for( i = 0; i < n; i++)
31   {
32    scanf("%s",stu[i].nam);
33    scanf("%d",&t);
34    sum = 0;
35    for( j = 0; j< t; j++)
36    {
37     scanf("%d",&x);
38     sum += fen[x-1];
39    }
40    if(sum >= g)
41     q++;
42    stu[i].score = sum;
43   }
44 
45   qsort(stu,n,sizeof(stu[0]),cmp);
46 
47   printf("%d\n",q);
48   for(i = 0; i < q; i++)
49    printf("%s %d\n",stu[i].nam,stu[i].score);
50  }
51  return 0;
52 }
原文地址:https://www.cnblogs.com/huzhenbo113/p/3003059.html