lxy_ayaka @ 2024-03-07 19:35:15
#include<bits/stdc++.h>
using namespace std;
struct shengri{
string name;
int year;
int month;
int day;
};
int n;
int main(){
//freopen("P1104.txt","r",stdin);
cin >> n;
shengri hhx[n+1];
for(int i=1;i<n+1;i++){
cin >> hhx[i].name;
cin >> hhx[i].year;
cin >> hhx[i].month;
cin >> hhx[i].day;
}
// for(int i=1;i<n+1;i++){
// cout << hhx[i].name <<endl;
// }
//
for(int i=1;i<n;i++){
if(hhx[i].year>hhx[i+1].year) {
// printf("%s-->%s\n",hhx[i].name.c_str(),hhx[i+1].name.c_str());
swap(hhx[i],hhx[i+1]);
}
else if(hhx[i].year=hhx[i+1].year){
if(hhx[i].month>hhx[i+1].month){
// printf("%s-->%s\n",hhx[i].name.c_str(),hhx[i+1].name.c_str());
swap(hhx[i],hhx[i+1]);
}
else if(hhx[i].month=hhx[i+1].month){
if(hhx[i].day>hhx[i+1].day) {
// printf("%s-->%s\n",hhx[i].name.c_str(),hhx[i+1].name.c_str());
swap(hhx[i],hhx[i+1]);
}
}
}
}
for(int i=1;i<n+1;i++){
cout << hhx[i].name <<endl;
}
}
by Star_Governor @ 2024-03-07 20:04:15
楼主,这个题要用结构体排序啊,用swap不方便
by lxy_ayaka @ 2024-03-25 18:31:01
@Star_Governor 喵喵喵
by Star_Governor @ 2024-03-25 18:36:39
@lxy_ayaka ?
by lxy_ayaka @ 2024-03-25 19:23:38
@Star_Governor 其实是谢谢大佬,已经ac了
by Star_Governor @ 2024-03-25 19:31:44
@lxy_ayaka 好的好的,祝你未来光辉灿烂!