解题思路:
注意事项:注意姓名字符串的长度要大于8,因为这个调了很多次
参考代码:#include
#include
#include
using namespace std;
struct student
{
int number;
char name[9];
int score;
} buf[100000];
bool cmp1(student a,student b)
{
return a.number
}
bool cmp2(student a,student b)
{
int tmp=strcmp(a.name,b.name);
if(tmp!=0)
{
return tmp<0;
}
else
{
return a.number
}
}
bool cmp3(student a,student b)
{
if(a.score!=b.score)
{
return a.score
}
else
{
return a.number
}
}
int main()
{
int n,c,num=0;
while(scanf(“%d%d”,&n,&c)!=EOF)
{
num++;
if(n>0)
{
for(int i=0;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
{
printf(“%06d %s %d\n”,buf[i].number,buf[i].name,buf[i].score);
}
}
else continue;
}
return 0;
}
版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。
发布者:全栈程序员栈长,转载请注明出处:https://javaforall.cn/189542.html原文链接:https://javaforall.cn