Andyliu2023 @ 2024-11-15 21:26:09
只得了64分,求助
#include <bits/stdc++.h>
using namespace std;
struct student{
char s[21];
int y,m,d;
}m[101];
bool operator<(student m1,student m2){
if(m1.y!=m2.y) return m1.y<m2.y;
if(m1.m!=m2.m) return m1.m<m2.m;
if(m1.d!=m2.d) return m1.d<m2.d;
}
int main(){
int n;
cin>>n;
for(int i=1;i<=n;i++)
cin>>m[i].s>>m[i].y>>m[i].m>>m[i].d;
stable_sort(m+1,m+n+1);
for(int i=1;i<=n;i++)
cout<<m[i].s<<endl;
return 0;
}
by qazsedcrfvgyhnujijn @ 2024-11-15 21:32:27
“(如果有两个同学生日相同,输入靠后的同学先输出)”
by yaonainai @ 2024-11-15 21:34:58
@Andyliu2023
#include <bits/stdc++.h>
using namespace std;
struct student{
char s[21];
int y,m,d,num;
}m[101];
bool operator<(student m1,student m2){
if(m1.y!=m2.y) return m1.y<m2.y;
if(m1.m!=m2.m) return m1.m<m2.m;
if(m1.d!=m2.d) return m1.d<m2.d;
return m1.num>m2.num;
}
int main(){
int n;
cin>>n;
for(int i=1;i<=n;i++)
{
cin>>m[i].s>>m[i].y>>m[i].m>>m[i].d;
m[i].num=i;
}
stable_sort(m+1,m+n+1);
for(int i=1;i<=n;i++)
cout<<m[i].s<<endl;
return 0;
}
by yaonainai @ 2024-11-15 21:38:48
如果有两个同学生日相同,输入靠后的同学先输出
QAQ
by Andyliu2023 @ 2024-11-15 21:40:28
@dqh_0616@qazsedcrfvgyhnujijn@yaonainai 非常感谢!!!