02: names of the students score highest output

Total time limit: 1000ms Memory Limit: 65536kB
describe
the number of students entered, and then enter the name of each student's scores and seeking to obtain the highest score of the student's name.

Input
of the first input line of a positive integer N (N <= 100), represents a number of students. Then N input lines of the following format:
Score name
score is a non-negative integer, and less than or equal to 100;
name is a string of continuous, no spaces, no more than 20 length.
Data to ensure only the highest score a student.
Output
obtain the name of the highest scores of the students.
Sample input
. 5
87 Lilei
99 Hanmeimei
97 Lily
96 Lucy
77 Jim
sample output
Hanmeimei
source
Problem (13-1)

#include<iostream>
#include<string>
using namespace std;
//定义学生结构体,包含姓名和成绩 
typedef struct stu{
	string name;
	int age;
};
int main(){
	int n;
	cin>>n;
	//输出n个学生的姓名和成绩 
	stu students[n+5];
	for(int i=1;i<=n;i++){
		cin>>students[i].age;
		cin>>students[i].name;
	}
	
	//遍历n个学生找出成绩最高的那个学生 
	stu maxStu=students[1];
	for(int i=1;i<=n;i++){
		if(students[i].age>maxStu.age){
			maxStu=students[i];
		}
	}
	//输出成绩最高的学生姓名 
	cout<<maxStu.name;
	return 0;
} 
Published 36 original articles · won praise 0 · Views 349

Guess you like

Origin blog.csdn.net/weixin_44437496/article/details/104040247