80pts!HELP!
查看原帖
80pts!HELP!
338147
01bit楼主2020/9/5 17:14
#include <cstdio>
#include <algorithm>
using namespace std;
struct student
{
    int id;
    int Chinese, maths, English;
} stus[300 + 1];
int n;
bool cmp(student a, student b)
{
    if (a.Chinese + a.maths + a.English == b.Chinese + b.maths + b.English)
    {
        if (a.Chinese == b.Chinese)
            return a.id < b.id;
        return a.Chinese > b.Chinese;
    }
    return a.Chinese + a.maths + a.English > b.Chinese + b.maths + b.English;
}
int main()
{
    scanf("%d", &n);
    for (int i = 1; i <= n; i++)
    {
        stus[i].id = i;
        scanf("%d%d%d", &(stus[i].Chinese), &(stus[i].maths), &(stus[i].English));
    }
    sort(&(stus[1]), &(stus[n]), cmp);
    for (int i = 1; i <= 5; i++)
        printf("%d %d\n", (stus[i].id), (stus[i].Chinese) + (stus[i].maths) + (stus[i].English));
    return 0;
}
2020/9/5 17:14
加载中...