a6b6c6d6 @ 2024-08-18 21:10:53
#include<bits/stdc++.h>
using namespace std;
struct tp{
string a;
int n,m,o,p;
};
tp s[105];
int main(){
int d;
cin>>d;
for(int i=1;i<=d;i++)s[i].p=i;
for(int i=1;i<=d;i++){
cin>>s[i].a>>s[i].n>>s[i].m>>s[i].o;
}
for(int i=0;i<=d*d;i++){
if(s[i].n<s[i-1].n)swap(s[i].p,s[i-1].p);
else if(s[i].n==s[i-1].n){
if(s[i].m<s[i-1].m)swap(s[i].p,s[i-1].p);
else if(s[i].m==s[i-1].m){
if(s[i].o<=s[i-1].o)swap(s[i].p,s[i-1].p);
}
}
}
for(int i=1;i<=d;i++){
for(int j=1;j<=d;j++){
if(s[j].p==i)cout<<s[j].a<<endl;
}
}
return 0;
}
by BlackWuKong @ 2024-08-18 21:14:05
@a6b6c6d6 结构体排序! sort!!!
by __Real_Madrid__ @ 2024-08-18 21:15:44
@a6b6c6d6 可以用sort排序啊! 求关QAQ
by a6b6c6d6 @ 2024-08-18 21:16:53
要是一样怎么办
by NOI_AK_I @ 2024-08-18 21:19:03
@a6b6c6d6 用
by pig1121 @ 2024-08-18 21:19:24
加一项 id
从小到大?
by NOI_AK_I @ 2024-08-18 21:19:26
@a6b6c6d6 球关QwQ
by BlackWuKong @ 2024-08-18 21:19:31
所以在sort里特判
by a6b6c6d6 @ 2024-08-18 21:21:22
@NOI_AK_I 好了
by BlackWuKong @ 2024-08-18 21:44:52
@a6b6c6d6
#include<bits/stdc++.h>
using namespace std;
struct node{
string name;
int y,m,d,id;
}a[110];
int n;
bool cmp(node a,node b){
if (a.y<b.y) return true;
if (a.y>b.y) return false;
if (a.y==b.y){
if (a.m<b.m) return true;
if (a.m>b.m) return false;
if (a.m==b.m){
if (a.d<b.d) return true;
if (a.d>b.d) return false;
if (a.d==b.d){
if(a.id>b.id) return true;
else return false;
}
}
}
}
int main(){
cin>>n;
for(int i=1;i<=n;i++){
cin>>a[i].name>>a[i].y>>a[i].m>>a[i].d;
a[i].id=i;
}
sort(a+1,a+n+1,cmp);
for(int i=1;i<=n;i++) cout<<a[i].name<<"\n";
return 0;
}
by BlackWuKong @ 2024-08-18 21:45:15
求关