当前位置:网站首页>【暑期每日一题】洛谷 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;
}边栏推荐
- Overview of the construction details of Meizhou veterinary laboratory
- STM32扩展板 数码管显示
- LeetCode_58(最后一个单词的长度)
- pytorch中常用数据集的使用方法
- JS to solve the problem of floating point multiplication precision loss
- Pytoch (I) -- basic grammar
- 最长递增子序列及最优解、动物总重量问题
- LeetCode_ 53 (maximum subarray and)
- Pytest automated testing - compare robotframework framework
- 解决:Thread 1:[<*>setValue:forUndefinedKey]:this class is not key value coding-compliant for the key *
猜你喜欢

STM32 光敏电阻传感器&两路AD采集
![AssertionError assert I.ndim == 4 and I.shape[1] == 3](/img/b1/0109bb0f893eb4c8915df36c100907.png)
AssertionError assert I.ndim == 4 and I.shape[1] == 3

CF1638E. Colorful operations Kodori tree + differential tree array

LM小型可编程控制器软件(基于CoDeSys)笔记十九:报错does not match the profile of the target

Pytorch(三) —— 函数优化

Dual contractual learning: text classification via label aware data augmentation reading notes

Pytest automated testing - compare robotframework framework

数据加载及预处理

扩展-Fragment

解决:拖动xib控件到代码文件中,报错setValue:forUndefinedKey:this class is not key value coding-compliant for the key
随机推荐
Tencent has five years of testing experience. It came to the interview to ask for 30K, and saw the so-called software testing ceiling
Solve the problem that the external chain file of Qiankun sub application cannot be obtained
AssertionError assert I.ndim == 4 and I.shape[1] == 3
Strategic suggestions and future development trend of global and Chinese vibration isolator market investment report 2022 Edition
Question bank and online simulation examination for special operation certificate of G1 industrial boiler stoker in 2022
2022 gas examination question bank and online simulation examination
LeetCode_58(最后一个单词的长度)
LeetCode_ 53 (maximum subarray and)
解决:Thread 1:[<*>setValue:forUndefinedKey]:this class is not key value coding-compliant for the key *
2022 G2 power station boiler stoker examination question bank and G2 power station boiler stoker simulation examination question bank
Maixll dock quick start
STM32 extended key scan
STM32 光敏电阻传感器&两路AD采集
I also gave you the MySQL interview questions of Boda factory. If you need to come in and take your own
Pytorch neural network construction template
分布式锁的实现
2022-02-15 (399. Division evaluation)
[hardware ten treasures catalogue] - reprinted from "hardware 100000 whys" (under continuous update ~ ~)
RDF query language SPARQL
分布式全局唯一ID解决方案详解