P5740 【深基7.例9】最厉害的学生

题目:

P5740 【深基7.例9】最厉害的学生 - 洛谷 | 计算机科学教育新生态 (luogu.com.cn)

代码:

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

typedef struct{
	string name;
	int ch,ma,en;
	int sum;
	int idx;
}student;
student s[1005];

//自定义排序函数 
bool cmp(student a,student b)
{
	if(a.sum!=b.sum)
	return a.sum>b.sum;  //先根据分数排名 
	else
	return a.idx<b.idx;//若分数相同,则根据序号排名 
}
int main()
{
	//加快cin cout的速度 
	std::ios::sync_with_stdio(false);
	cin.tie(0);cout.tie(0);
	
	int n;
	cin>>n;
	for(int i=0;i<n;i++)
	{
		cin>>s[i].name>>s[i].ch>>s[i].ma>>s[i].en;
		s[i].sum=s[i].ch+s[i].ma+s[i].en;
		s[i].idx=i;
	}
	sort(s,s+n,cmp);
	cout<<s[0].name<<" "<<s[0].ch<<" "<<s[0].ma<<" "<<s[0].en;
	return 0;
}

相关推荐

  1. P57407.9厉害学生

    2024-03-26 10:48:04       26 阅读
  2. P57447.习9】培训

    2024-03-26 10:48:04       38 阅读
  3. P57437.习8】猴子吃桃

    2024-03-26 10:48:04       37 阅读
  4. P5729 【5.7】工艺品制作

    2024-03-26 10:48:04       32 阅读
  5. P5737】【7.3】闰年展示

    2024-03-26 10:48:04       21 阅读
  6. P5705 【2.7】数字反转题解

    2024-03-26 10:48:04       36 阅读
  7. P5707 【2.12】上学迟到题解

    2024-03-26 10:48:04       39 阅读
  8. P5719 【4.3】分类平均

    2024-03-26 10:48:04       28 阅读

最近更新

  1. TCP协议是安全的吗?

    2024-03-26 10:48:04       19 阅读
  2. 阿里云服务器执行yum,一直下载docker-ce-stable失败

    2024-03-26 10:48:04       20 阅读
  3. 【Python教程】压缩PDF文件大小

    2024-03-26 10:48:04       20 阅读
  4. 通过文章id递归查询所有评论(xml)

    2024-03-26 10:48:04       20 阅读

热门阅读

  1. 3544: 【C1】【基础】输出小数部分

    2024-03-26 10:48:04       20 阅读
  2. 九、Spring源码学习之initApplicationEventMulticaster方法

    2024-03-26 10:48:04       21 阅读
  3. AI:133-基于深度学习的工业质检自动化

    2024-03-26 10:48:04       21 阅读
  4. HCSC单片机使用小结

    2024-03-26 10:48:04       18 阅读
  5. 笔记:Linux下的snmp配置

    2024-03-26 10:48:04       18 阅读
  6. OJ : 1091 : 童年生活二三事(多实例测试)

    2024-03-26 10:48:04       21 阅读
  7. 如何查看ubuntu服务器上防火墙信息

    2024-03-26 10:48:04       17 阅读
  8. web3 token 如何理解

    2024-03-26 10:48:04       15 阅读
  9. Web3创作整理 - 2024-02-23 ~ 2024-03-25

    2024-03-26 10:48:04       20 阅读
  10. 微服务常用技术栈

    2024-03-26 10:48:04       17 阅读
  11. python中良好的编码规范

    2024-03-26 10:48:04       17 阅读
  12. 前端几种下载文件的方式(url方式和文件流方式)

    2024-03-26 10:48:04       21 阅读