Just look at the code,that's OK;
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <algorithm>
using namespace std;
struct student
{
char name[20];
int total;
int chinese;
int math;
}a[1005];
bool cmp(student x,student y)
{
if(x.total>y.total)
return 1;
else if(x.total==y.total)
{
if(x.chinese>y.chinese)
return 1;
else if(x.chinese==y.chinese)
{
if(x.math>y.math)
return 1;
}
}
return 0;
}
int main()
{
int n,i;
scanf("%d",&n);
for(i=0;i<n;i++)
{
scanf("%s %d %d %d",a[i].name,&a[i].total,&a[i].chinese,&a[i].math);
}
sort(a,a+n,cmp);
for(i=0;i<n;i++)
{
printf("%s\n",a[i].name);
}
return 0;
}

本文介绍了一个使用C++编写的程序,该程序能够读取学生的姓名、总分、语文和数学成绩,并按照特定条件对学生信息进行排序。排序首先依据总分从高到低,总分相同时则按语文成绩从高到低,再相同则按数学成绩从高到低。通过这个程序,可以快速了解学生们的学术表现。

被折叠的 条评论
为什么被折叠?



