/* @问题:考试排名 @time:20160426 @author:alex 结构体 成员为指针时需要初始化动态分配地址 */ #include<stdio.h> #include<string.h> #include<stdlib.h> //#define ext_input typedef struct ranking { char name[20]; char acMessage[100]; int ac_count; int score; } rankingType; int compare(const void*p1,const void*p2) { rankingType * A = (rankingType *)p1; rankingType * B = (rankingType *)p2; //if(A->ac_count != B->ac_count) // return A->ac_count < B->ac_count; //return A->score > B->score; if (A->ac_count != B->ac_count) { return A->ac_count < B->ac_count; } else if (A->score != B->score) { return A->score > B->score ; } else { return (A->name > B->name); } } int main() { rankingType rank[1000]; int n,m; int count; int number_count; int length,score,count_len; #ifdef ext_input freopen("2093.txt","r",stdin); freopen("out.txt","w",stdout); #endif while(scanf("%d%d",&n,&m) != EOF) { number_count = 0; while(scanf("%s",rank[number_count].name)!=EOF) { rank[number_count].ac_count = 0; rank[number_count].score =0; for(count =0;count <n;count++) { length=0; score=0; count_len =0; scanf("%s",rank[number_count].acMessage); //没提交与都是错的 AC count不计数 if(!strcmp(rank[number_count].acMessage,"0")) { continue; } if(*(rank[number_count].acMessage) == '-') { continue; } rank[number_count].ac_count++; length = strlen(rank[number_count].acMessage); if(!strstr(rank[number_count].acMessage,"("))//没有( { while(*(rank[number_count].acMessage+count_len)) { score = score*10 + *(rank[number_count].acMessage+count_len)-'0'; count_len++; } rank[number_count].score += score; continue; } while(*(rank[number_count].acMessage+count_len) != '(')//有括号算出提交时间 { score = score*10 + *(rank[number_count].acMessage+count_len)-'0'; count_len++; } rank[number_count].score += score; score = 0; count_len++; while(*(rank[number_count].acMessage+count_len) != ')')//计算罚时 { score = score*10 + *(rank[number_count].acMessage+count_len)-'0'; count_len++; } score = score * m; rank[number_count].score += score; } number_count++; } qsort(rank,number_count,sizeof(rankingType),compare); for(count = 0; count<number_count; count++) { printf("%-10s%3d%5d\n",rank[count].name,rank[count].ac_count,rank[count].score); } } #ifdef ext_input fclose(stdout); fclose(stdin); #endif return 0; }