02: Output the name of the student with the highest score
Total time limit:
1000ms
Memory limit:
65536kB
describe
Enter the number of students, and then enter each student's score and name to find the name of the student with the highest score.
enter
The first line enters a positive integer N (N <= 100), indicating the number of students. Then enter N lines, each line format is as follows:
Score Name
Score is a non-negative integer less than or equal to 100;
Name is a continuous string with no spaces in between and the length does not exceed 20.
The data guarantees that there is only one student with the highest score.
output
The name of the classmate who received the highest score.
sample input
5
87 lilei
99 hanmeimei
97 lily
96 lucy
77 jim
sample output
Hanmeimei
#include <iostream>
using namespace std;
#define N 105
struct stu {
int score;
string name;
};
int main()
{
int n, max = 0;
stu student[N];
string hight_name;
cin >> n;
for (int i = 0; i < n; i++)
{
cin >> student[i].score >> student[i].name;
if (student[i].score > max)
{
max = student[i].score;
hight_name = student[i].name;
}
}
cout << hight_name << endl;
return 0;
}