hdu 1236 排名

结构体定义没搞明确,一直WA。最终AC了,真是高兴呀大笑

代码例如以下:

#include<stdio.h>
#include<stdlib.h>
#include<string.h>
 struct student
{
  char id[30];
  int  score;
}person[1001];
int cmp(const void *a,const void *b)
{
    struct student *aa=(struct student *)a;
     struct student *bb=(struct student *)b;
    if(aa->score!=bb->score)
        return bb->score-aa->score;
    else
        return  strcmp(aa->id,bb->id);
}
int main()
{
    int N,M,G,i,title[11],sum,tihao[10],m,j;
    
   while( scanf("%d%d%d",&N,&M,&G)!=EOF,N)
   {
     int count=0;
     for(i=1;i<=1001;i++)
     person[i].score=0;
     for(i=1;i<=M;i++)
       scanf("%d",&title[i]);
     for(i=1;i<=N;i++)
       {
          
          scanf("%s%d",person[i].id,&m);
          for(j=1;j<=m;j++)
             {
               scanf("%d",&tihao[j]);
               person[i].score+=title[tihao[j]];
             }
       }
       qsort(person+1,N,sizeof(person[1]),cmp);
       for(i=1;i<=N;i++)
       {
          if(person[i].score>=G)
          count++;
       }
       printf("%d
",count);
       for(i=1;i<=N;i++)
       {
         if(person[i].score>=G)
         printf("%s %d
",person[i].id,person[i].score);
       }
   }
    return 0;
    
} 


原文地址:https://www.cnblogs.com/mfrbuaa/p/5171495.html