题解 | 队伍成绩排名

队伍成绩排名

https://www.nowcoder.com/practice/33ce1e1a562d4a8d85e610544fad2cdd

#include<iostream>
#include<algorithm>

using namespace std;
struct Team {
    int score, time;
    string name;
};

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n;
    cin >> n;
    Team teams[n];
    for (int i = 0; i < n; i++) {
        string s;
        cin >> s;
        int time = 0, score = 0;
        for (int i = 0; i < 10; i++) {
            char c;
            cin >> c;
            if (c == 'A') {
                int x;
                cin >> x;
                time += x;
                score++;
            }
        }
        teams[i] = {score, time, s};
    }
    sort(teams, teams + n, [](const auto & a, const auto & b) {
        if (a.score != b.score) return a.score > b.score;
        else if (a.time != b.time) return a.time < b.time;
        else return a.name < b.name;
    });
    for_each(teams, teams + n,
    [](const auto & team) {
        cout << team.name << ' ' << team.score << ' ' << team.time << endl;
    });
    return 0;
}

全部评论

相关推荐

2025-12-08 18:11
曲阜师范大学 Java
程序员花海_:实习和校招简历正确格式应该是教育背景+实习+项目经历+个人评价 其中项目经历注意要体现业务 实习经历里面的业务更是要自圆其说 简历模板尽可能保持干净整洁 不要太花哨的
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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