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.
|
|
|
|
#include <bits/stdc++.h>
|
|
|
|
|
|
|
|
|
|
using namespace std;
|
|
|
|
|
|
|
|
|
|
struct Student {
|
|
|
|
|
string name;
|
|
|
|
|
string xb;
|
|
|
|
|
int year;
|
|
|
|
|
int month;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
//对比的方法
|
|
|
|
|
/*
|
|
|
|
|
用大于号就是从大到小排序,用小于号就是从小到大排序
|
|
|
|
|
*/
|
|
|
|
|
bool compare(const Student &x, const Student &y) {
|
|
|
|
|
if (x.year == y.year) return x.month > y.month;
|
|
|
|
|
return x.year > y.year;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int main() {
|
|
|
|
|
int n;
|
|
|
|
|
cin >> n;
|
|
|
|
|
//声明动态数组
|
|
|
|
|
Student *a = new Student[n];
|
|
|
|
|
for (int i = 0; i < n; ++i) {
|
|
|
|
|
cin >> a[i].name >> a[i].xb >> a[i].year >> a[i].month;
|
|
|
|
|
}
|
|
|
|
|
//找到年龄最小的人员
|
|
|
|
|
/*
|
|
|
|
|
此函数有3个参数:
|
|
|
|
|
参数1:第一个参数是数组的首地址,一般写上数组名就可以,因为数组名是一个指针常量。
|
|
|
|
|
参数2:第二个参数相对较好理解,即首地址加上数组的长度n(代表尾地址的下一地址)。
|
|
|
|
|
参数3:默认可以不填,如果不填sort会默认按数组升序排序。也就是1,2,3,4排序。也可以自定义一个排序函数,
|
|
|
|
|
改排序方式为降序什么的,也就是4,3,2,1这样。
|
|
|
|
|
*/
|
|
|
|
|
sort(a, a + n, compare);
|
|
|
|
|
//输出结果
|
|
|
|
|
cout << a[0].name << " " << a[0].xb << " " << a[0].year << " " << a[0].month << endl;
|
|
|
|
|
//删除动态数组
|
|
|
|
|
delete[]a;
|
|
|
|
|
return 0;
|
|
|
|
|
}
|