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.

44 lines
1.3 KiB

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

#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;
}