CSP历年复赛题-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;
}
分类:
CSP-J复赛真题解析
标签:
排序
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· 阿里巴巴 QwQ-32B真的超越了 DeepSeek R-1吗?
· 【译】Visual Studio 中新的强大生产力特性
· 张高兴的大模型开发实战:(一)使用 Selenium 进行网页爬虫
· 【设计模式】告别冗长if-else语句:使用策略模式优化代码结构