#include<iostream>
#include<algorithm>
#include<string>
using namespace std;
struct Person
{
int code;
string name;
string birthday;
}person[100];
int n;
bool compare(const Person& a, const Person& b)
{
if (a.birthday < b.birthday || a.birthday == b.birthday && a.code>b.code)
return true;
else
return false;
}
int main()
{
string year, month, day;
cin >> n;
for (int i = 0; i < n; i++)
{
person[i].code = i;
cin >> person[i].name >> year >> month >> day;
if (month.length() == 2 && day.length() == 2)
person[i].birthday = year + month + day;
else if (month.length() == 1 && day.length() == 2)
person[i].birthday = year + '0' + month + day;
else if (month.length() == 2 && day.length() == 1)
person[i].birthday = year + month + '0' + day;
else if (month.length() == 1 && day.length() == 1)
person[i].birthday = year + '0' + month + '0' + day;
}
sort(person, person + n, compare);
for (int i = 0; i < n; i++)
cout << person[i].name << endl;
return 0;
}
洛谷P1104 生日进阶解法
最新推荐文章于 2025-10-20 21:05:32 发布
这是一个C++程序,用于读取n个人的姓名、生日和编码,并根据生日和编码进行升序排序。程序首先处理输入的日期格式,然后使用sort函数和自定义比较函数进行排序,最后打印出排序后的人员姓名。
997

被折叠的 条评论
为什么被折叠?



