2460: 【普及-】【P5740】最厉害的学生

内存限制:128 MB 时间限制:1.000 S
评测方式:文本比较 命题人:
提交:31 解决:17

题目描述

现有 lns="http://www.w3.org/1998/Math/MathML"> 名同学参加了期末考试,并且获得了每名同学的信息:姓名(不超过 lns="http://www.w3.org/1998/Math/MathML">8 个字符的仅有英文小写字母的字符串)、语文、数学、英语成绩(均为不超过 lns="http://www.w3.org/1998/Math/MathML">150 的自然数)。总分最高的学生就是最厉害的,请输出最厉害的学生各项信息(姓名、各科成绩)。如果有多个总分相同的学生,输出靠前的那位。

输入

第一行输入一个正整数 lns="http://www.w3.org/1998/Math/MathML">,表示学生个数。

第二行开始,往下 lns="http://www.w3.org/1998/Math/MathML"> 行,对于每一行首先先输入一个字符串表示学生姓名,再输入三个自然数表示语文、数学、英语的成绩。均用空格相隔。

输出

输出最厉害的学生。

样例输入 复制

3
senpai 114 51 4
lxl 114 10 23
fafa 51 42 60

样例输出 复制

senpai 114 51 4

提示

数据保证,lns="http://www.w3.org/1998/Math/MathML">11000,姓名为长度不超过 lns="http://www.w3.org/1998/Math/MathML">8 的字符串,语文、数学、英语成绩均为不超过 lns="http://www.w3.org/1998/Math/MathML">150 的自然数。



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

struct student {
	string name;
	int chinese,math,english;  //定义一个结构体记录每个学生的信息 
}a,ans;
//或者 struct student a,ans;
int main(){
	int n;
	cin>>n;
	for (int i=1;i<=n;i++) {
		cin>>a.name>>a.chinese>>a.math>>a.english;
		if (i==1) ans=a;  
        //比较两个结构体的大小,如果这个更大,就用这个来更新答案 
		if (a.chinese+a.math+a.english>ans.chinese+ans.math+ans.english) ans=a; 
	}
	cout<<ans.name<<" "<<ans.chinese<<" "<<ans.math<<" "<<ans.english<<endl;
	return 0;
}