题目连接:php
http://acm.hdu.edu.cn/showproblem.php?pid=1862函数
题目类型:测试
模拟-结构体排序spa
题意归纳:code
给出N我的的学号,名字,成绩,经过不一样的顺序进行不一样的排序:blog
第一种排序:按学号递增排序排序
第二种排序:按姓名的非递减字典序排序ip
第三种排序:按成绩的非递减排序。当若干学生具备相同姓名或者相同成绩时,则按他们的学号递增排序。字符串
解题思路:string
经过结构体将全部人的信息储存起来,而后经过不一样的排序方法,写出不一样的cmp函数,而后在sort一波输出便可。
题目:
Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 19453 Accepted Submission(s): 7176
# include <stdio.h> # include <string.h> # include <algorithm> using namespace std; struct student{ int id; char name[20]; int score; }s[100010]; int cmp1(student a,student b) { if(a.id<b.id) return 1; return 0; } int cmp2(student a,student b) { if(strcmp(a.name,b.name)<0) return 1; else if(strcmp(a.name,b.name)==0 && a.id<b.id) return 1; return 0; } int cmp3(student a,student b) { if(a.score<b.score) return 1; else if(a.score==b.score && a.id<b.id) return 1; return 0; } int main () { int n,c,i,num=0; while(scanf("%d%d",&n,&c),n) { num++; for(i=0;i<n;i++) scanf("%d %s %d",&s[i].id,s[i].name,&s[i].score); if(c==1) sort(s,s+n,cmp1); else if(c==2) sort(s,s+n,cmp2); else if(c==3) sort(s,s+n,cmp3); printf("Case %d:\n",num); for(i=0;i<n;i++) printf("%06d %s %d\n",s[i].id,s[i].name,s[i].score); } return 0; }