洛谷题单指南-排序-P1093 [NOIP2007 普及组] 奖学金

原题链接:https://www.luogu.com.cn/problem/P1093

题意解读:本题考察排序,根据题意,先按总分从大到小排,再按语文从大到小排,以上都相同则按学号从小到大排。

100分代码:

#include <bits/stdc++.h>
using namespace std;

const int N = 305;

struct student
{
    int id;
    int yuwen;
    int shuxue;
    int yingyu;
    int total;
} s[N];

bool cmp(student s1, student s2)
{
    if(s1.total != s2.total) return s1.total > s2.total;
    if(s1.yuwen != s2.yuwen) return s1.yuwen > s2.yuwen;
    return s1.id < s2.id;
}

int n;

int main()
{
    cin >> n;
    for(int i = 1; i <= n; i++)
    {
        s[i].id = i;
        cin >> s[i].yuwen >> s[i].shuxue >> s[i].yingyu;
        s[i].total = s[i].yuwen + s[i].shuxue + s[i].yingyu;
    }

    sort(s + 1, s + n + 1, cmp);

    for(int i = 1; i <= 5; i++) cout << s[i].id << " " << s[i].total << endl;

    return 0;
}

 

posted @   五月江城  阅读(54)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 分享一个免费、快速、无限量使用的满血 DeepSeek R1 模型,支持深度思考和联网搜索!
· 基于 Docker 搭建 FRP 内网穿透开源项目(很简单哒)
· ollama系列1:轻松3步本地部署deepseek,普通电脑可用
· 按钮权限的设计及实现
· 【杂谈】分布式事务——高大上的无用知识?
点击右上角即可分享
微信分享提示