yanda25 @ 2024-03-11 17:22:11
#include <iostream>
using namespace std;
struct birthday{
string name;
int y,m,d,num;
};
int main(){
int n,cnt = 0;
cin >> n;
struct birthday prime[n + 1];
for(int i = 1;i <= n;i++){
cin >> prime[i].name >> prime[i].y >> prime[i].m >> prime[i].d;
prime[i].num = n - i;
}
for(int i = 1;i < n;i++){
for(int j = 1;j <= n - i;j++){
if(prime[j].y > prime[j + 1].y || prime[j].y == prime[j + 1].y && prime[j].m > prime[j + 1].m || prime[j].y == prime[j + 1].y && prime[j].m == prime[j + 1].m && prime[j].d > prime[j + 1].d){
swap(prime[j].name,prime[j + 1].name);
swap(prime[j].y,prime[j + 1].y);
swap(prime[j].m,prime[j + 1].m);
swap(prime[j].d,prime[j + 1].d);
}
}
}
for(int i = 1;i <= n;i++){
if(prime[i].y == prime[i + 1].y && prime[i].m == prime[i + 1].m && prime[i].d == prime[i + 1].d){
if(prime[i].num > prime[i + 1].num){
swap(prime[i].name,prime[i + 1].name);
swap(prime[i].y,prime[i + 1].y);
swap(prime[i].m,prime[i + 1].m);
swap(prime[i].d,prime[i + 1].d);
}
}
}
for(int i = 1;i <= n;i++)cout << prime[i].name << endl;
return 0;
}
by RainCQwQ @ 2024-03-11 17:36:26
可以使用 sort + cmp 更方便