http://acm.hdu.edu.cn/showproblem.php?pid=3293
水一道排序题。。。希望今晚tc好运~
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
#include <stdio.h> #include <stdlib.h> #include <string.h> typedef struct L{ char location[20],type[20],level[20] ; int ll ; }L ; L kk[501] ; int cmp(const void*a,const void*b) { L*c=(L*)a ; L*d=(L*)b ; if(!strcmp(c->location,d->location)) { if(c->ll==d->ll) return strcmp(c->type,d->type) ; return d->ll-c->ll ; } return strcmp(c->location,d->location) ; } int main() { int n ; int nCase=1 ; while(~scanf("%d",&n)) { for(int i=0;i<n;i++) { scanf("%s%s%s",kk[i].type,kk[i].location,kk[i].level) ; if(kk[i].level[0]=='w') kk[i].ll=3 ; if(kk[i].level[0]=='g') kk[i].ll=2 ; if(kk[i].level[0]=='s') kk[i].ll=1 ; } qsort(kk,n,sizeof(L),cmp) ; printf("Case %d\n",nCase++) ; printf("%s:\n",kk[0].location) ; printf(" %s %s\n",kk[0].type,kk[0].level) ; for(int i=1;i<n;i++) { if(!strcmp(kk[i].location,kk[i-1].location)) printf(" %s %s\n",kk[i].type,kk[i].level) ; else printf("%s:\n %s %s\n",kk[i].location,kk[i].type,kk[i].level) ; } } return 0 ; }