You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
36 lines
650 B
36 lines
650 B
#include <bits/stdc++.h>
|
|
|
|
using namespace std;
|
|
struct Student {
|
|
string name;
|
|
float score;
|
|
};
|
|
|
|
|
|
//对比的方法
|
|
/*
|
|
用大于号就是从大到小排序,用小于号就是从小到大排序
|
|
*/
|
|
bool compare(const Student &x, const Student &y) {
|
|
return x.score > y.score;
|
|
}
|
|
|
|
|
|
int main() {
|
|
int n;
|
|
cin >> n;
|
|
//利用指针动态声明结构体数组
|
|
Student *s = new Student[n];
|
|
for (int i = 0; i < n; ++i) {
|
|
cin >> s[i].score >> s[i].name;
|
|
}
|
|
//排序
|
|
sort(s, s + n, compare);
|
|
cout << s[0].name << endl;
|
|
|
|
//删除指针数组
|
|
delete[]s;
|
|
|
|
return 0;
|
|
}
|