HDU 2093 - 考试排名
2011-11-09 23:37
429 查看
知识点:结构体三级排序
其实只要懂了二级排序,其它的不管几级只要类推就行了。
![](http://hi.csdn.net/attachment/201111/10/0_1320900854mHN7.gif)
其实只要懂了二级排序,其它的不管几级只要类推就行了。
#include <cstdio> #include <cstring> #include <cstdlib> struct Student { char name[11]; int num; int time; }stu[100]; inline int cmp(const void *a,const void *b) { Student *c=(Student *)a; Student *d=(Student *)b; if(c->num!=d->num) return d->num-c->num; //先按num从大到小 else if(c->time!=d->time) return c->time-d->time; //再按time从小到大 else return strcmp(c->name,d->name); //最后按name的字典序 } int main() { int n,m,cnt=0; scanf("%d%d",&n,&m); while(scanf("%s",stu[cnt].name)!=EOF) { stu[cnt].num=stu[cnt].time=0; for(int i=0;i<n;i++) { int temp; scanf("%d",&temp); if(temp>0) { stu[cnt].num++; stu[cnt].time+=temp; if(getchar()=='(') { scanf("%d",&temp); stu[cnt].time+=temp*m; getchar(); } } } cnt++; } qsort(stu,cnt,sizeof(stu[0]),cmp); for(int i=0;i<cnt;++i) printf("%-10s %2d %4d\n",stu[i].name,stu[i].num,stu[i].time); return 0; }
![](http://hi.csdn.net/attachment/201111/10/0_1320900854mHN7.gif)
![](http://hi.csdn.net/attachment/201111/9/0_13208531702EN6.gif)
相关文章推荐
- HDU 2093 考试排名 模拟题
- hdu 2093 考试排名
- HDU 2093 考试排名【结构体排序】
- hdu 2093 考试排名
- HDU 2093(考试排名)解题纠错
- HDU 2093 考试排名
- HDU 杭电 acm-2093-考试排名
- HDU——2093考试排名(string类及其函数的运用以及istringstream)
- HDU ACM 2093 考试排名
- HDOJ(HDU) 2093 考试排名(Arrays.sort排序、类的应用)
- HDU 2093 考试排名
- HDOJ(HDU) 2093 考试排名(Arrays.sort排序、类的应用)
- hdu 2093 考试排名(结构体排序)
- HDU 2093 考试排名
- HDU 2093 (考试排名)
- hdu 2093 考试排名 解题报告
- HDU 2093 考试排名
- hdu 2093 考试排名
- HDOJ HDU 2093 考试排名 ACM 2093 IN HDU
- 【hdu 2093】 考试排名