题解 | 奖学金-NOIP2007普及组复赛

奖学金

https://ac.nowcoder.com/acm/contest/235/A

算法知识点: 排序,多关键字排序

复杂度:

解题思路:

多关键字排序即可。

C++ 代码:

#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
 
using namespace std;
 
const int N = 310;
 
struct Person
{
    int chinese, math, english;
    int total;
    int id;
    bool operator< (const Person& W)const
    {
        if (total != W.total) return total > W.total;
        if (chinese != W.chinese) return chinese > W.chinese;
        return id < W.id;
    }
}person[N];
 
int main()
{
    int n;
    scanf("%d", &n);
    for (int i = 1; i <= n; i ++ )
    {
        int chinese, math, english;
        scanf("%d%d%d", &chinese, &math, &english);
        int total = chinese + math + english;
        person[i] = {chinese, math, english, total, i};
    }
 
    sort(person + 1, person + 1 + n);
 
    for (int i = 1; i <= 5; i ++ ) printf("%d %d\n", person[i].id, person[i].total);
    return 0;
}


另外,牛客暑期NOIP真题班限时免费报名
报名链接:https://www.nowcoder.com/courses/cover/live/248
报名优惠券:DCYxdCJ
全部评论

相关推荐

01-11 08:47
门头沟学院 Java
choumoduji...:读研的目的就是为了以最快的速度和最低的要求完成“学校”规定的毕业标准,而不是所谓课题组的要求
点赞 评论 收藏
分享
评论
1
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务