解题思路:
注意事项:
注意姓名字符串的长度要大于8,因为这个调了很多次
参考代码:
#include<stdio.h> #include<algorithm> #include<string.h> using namespace std; struct student { int number; char name[9]; int score; } buf[100000]; bool cmp1(student a,student b) { return a.number<b.number; } bool cmp2(student a,student b) { int tmp=strcmp(a.name,b.name); if(tmp!=0) { return tmp<0; } else { return a.number<b.number; } } bool cmp3(student a,student b) { if(a.score!=b.score) { return a.score<b.score; } else { return a.number<b.number; } } int main() { int n,c,num=0; while(scanf("%d%d",&n,&c)!=EOF) { num++; if(n>0) { for(int i=0;i<n;i++) { scanf("%d%s%d",&buf[i].number,buf[i].name,&buf[i].score); } if(c==1) { sort(buf,buf+n,cmp1); } else if(c==2) { sort(buf,buf+n,cmp2); } else if(c==3) { sort(buf,buf+n,cmp3); } printf("Case %d:\n",num); for(int i=0;i<n;i++) { printf("%06d %s %d\n",buf[i].number,buf[i].name,buf[i].score); } } else continue; } return 0; }
0.0分
4 人评分
点我有惊喜!你懂得!浏览:1395 |
C语言程序设计教程(第三版)课后习题7.4 (C语言代码)浏览:560 |
震宇大神的杀毒软件 (C语言代码)浏览:1241 |
简单的a+b (C语言代码)浏览:647 |
C语言程序设计教程(第三版)课后习题7.3 (C语言代码)浏览:625 |
C语言程序设计教程(第三版)课后习题5.7 (C语言代码)浏览:617 |
printf基础练习2 (C语言代码)浏览:748 |
【计算两点间的距离】 (C语言代码)浏览:1494 |
C语言程序设计教程(第三版)课后习题1.6 (C语言代码)浏览:476 |
C语言程序设计教程(第三版)课后习题5.5 (C语言代码)浏览:558 |