当前位置:网站首页>【暑期每日一题】洛谷 P5740【深基7.例9】最厉害的学生
【暑期每日一题】洛谷 P5740【深基7.例9】最厉害的学生
2022-07-01 04:47:00 【AC_Dragon】
题目链接:P5740 【深基7.例9】最厉害的学生 - 洛谷 | 计算机科学教育新生态 (luogu.com.cn)
题目描述
现有 N(N <= 1000)名同学参加了期末考试,并且获得了每名同学的信息:姓名(不超过 8 个字符的仅有英文小写字母的字符串)、语文、数学、英语成绩(均为不超过 150 的自然数)。总分最高的学生就是最厉害的,请输出最厉害的学生各项信息(姓名、各科成绩)。如果有多个总分相同的学生,输出靠前的那位。
输入格式
无
输出格式
无
样例 #1
样例输入 #1
3
senpai 114 51 4
lxl 114 10 23
fafa 51 42 60样例输出 #1
senpai 114 51 4本题主要考察struct结构体和sort排序。
AC code:
#include<iostream>
#include<algorithm>
using namespace std;
struct st // 定义一个结构体st
{
int id; // 编号
string name; // 姓名
int Ch; // 语文
int Ma; // 数学
int Eng; // 英语
int total; // 总分
};
bool cmp(st a,st b)
{
if(a.total>b.total)
return true;
else if(a.total==b.total && a.id<b.id)
return true;
else
return false;
}
/* 与上面cmp函数等价,两种cmp函数任选其一
bool cmp(st a,st b)
{
if(a.total==b.total)
return a.id<b.id;
else
return a.total>b.total;
}*/
int main()
{
int n;
cin>>n;
struct st s[n]; // 定义一个结构体数组s
for(int i=0;i<n;i++)
{
s[i].id=i;
cin>>s[i].name>>s[i].Ch>>s[i].Ma>>s[i].Eng;
s[i].total=s[i].Ch+s[i].Ma+s[i].Eng;
}
sort(s,s+n,cmp); // 调用sort函数进行快速排序
cout<<s[0].name<<" "<<s[0].Ch<<" "<<s[0].Ma<<" "<<s[0].Eng<<endl;
return 0;
}边栏推荐
- pytorch 卷积操作
- 手动实现一个简单的栈
- LeetCode_28(实现 strStr())
- Seven crimes of counting software R & D Efficiency
- LeetCode_58(最后一个单词的长度)
- 2022 tea master (intermediate) examination question bank and tea master (intermediate) examination questions and analysis
- 科研狗可能需要的一些工具
- pytorch中常用数据集的使用方法
- [difficult] sqlserver2008r2, can you recover only some files when recovering the database?
- Some tools that research dogs may need
猜你喜欢

技术分享| 融合调度中的广播功能设计

Section 27 remote access virtual private network workflow and experimental demonstration

无器械健身

神经网络-非线性激活

The index is invalid

How to do the performance pressure test of "Health Code"

2022 gas examination question bank and online simulation examination

Pytoch (I) -- basic grammar

分布式架构系统拆分原则、需求、微服务拆分步骤

LM small programmable controller software (based on CoDeSys) note 19: errors do not match the profile of the target
随机推荐
Quelques outils dont les chiens scientifiques pourraient avoir besoin
AssertionError assert I.ndim == 4 and I.shape[1] == 3
Basic usage, principle and details of session
js解决浮点数相乘精度丢失问题
RuntimeError: “max_pool2d“ not implemented for ‘Long‘
Daily algorithm & interview questions, 28 days of special training in large factories - the 13th day (array)
Dede collection plug-in does not need to write rules
How to use common datasets in pytorch
The longest increasing subsequence and its optimal solution, total animal weight problem
Shell之分析服务器日志命令集锦
JVM栈和堆简介
Difficulties in the development of knowledge map & the importance of building industry knowledge map
The junior college students were angry for 32 days, four rounds of interviews, five hours of soul torture, and won Ali's offer with tears
先有网络模型的使用及修改
分布式-总结列表
【硬十宝典】——2.【基础知识】开关电源各种拓扑结构的特点
Registration of P cylinder filling examination in 2022 and analysis of P cylinder filling
Dataloader的使用
2022-02-15 (399. Division evaluation)
2022 t elevator repair new version test questions and t elevator repair simulation test question bank