str2011 @ 2024-05-23 22:09:42
80分
#include <iostream>
#include <algorithm>
#include <cstring>
using namespace std;
struct stu{
string name;
int y,m,d;
void read(){
cin>>name>>y>>m>>d;
}
}a[1000010];
bool cmp(stu x,stu y){
if(x.y!=y.y)return x.y<y.y;
else if(x.m!=y.m)return x.m<y.m;
return x.d<y.d;
}
int main(){
int n;
cin>>n;
for(int i=1;i<=n;i++){
a[i].read();
}
sort(a+1,a+n+1,cmp);
for(int i=1;i<=n;i++){
cout<<a[i].name<<endl;
}
return 0;
}
by Ravener @ 2024-05-23 22:13:53
如果有两个同学生日相同,输入靠后的同学先输出。
要加个学生序号,靠后的先输出
by str2011 @ 2024-05-23 22:14:26
好吧,虽然ac了,但大佬们还可以指出问题
by Ravener @ 2024-05-23 22:14:37
struct stu{
string name;
int y,m,d,t;
void read(){
cin>>name>>y>>m>>d;
}
}a[1000010];
bool cmp(stu x,stu y){
if(x.y!=y.y)return x.y<y.y;
else if(x.m!=y.m)return x.m<y.m;
else if(x.d!=y.d)return x.d<y.d;
else return x.t>y.t;
}
int main(){
int n;
cin>>n;
for(int i=1;i<=n;i++){
a[i].read();
a[i].t=i;
}
sort(a+1,a+n+1,cmp);
for(int i=1;i<=n;i++){
cout<<a[i].name<<endl;
}
return 0;
}
by Ravener @ 2024-05-23 22:14:46
@str2011
by LZYAC @ 2024-05-23 22:16:56
你是没有注意到:排名靠后的先输出。
所以只要在cmp和结构体里改一下即可。
送上代码:(看//)
#include <iostream>
#include <algorithm>
#include <cstring>
using namespace std;
struct stu{
string name;
// int y,m,d,num;
void read(){
cin>>name>>y>>m>>d;
}
}a[1000010];
bool cmp(stu x,stu y){
if(x.y!=y.y)return x.y<y.y;
else if(x.m!=y.m)return x.m<y.m;
// else if(x.d!=y.d)return x.d<y.d;
// return x.num>y.num;
}
int main(){
int n;
cin>>n;
for(int i=1;i<=n;i++){
a[i].read();
// a[i].num=i;
}
sort(a+1,a+n+1,cmp);
for(int i=1;i<=n;i++){
cout<<a[i].name<<endl;
}
return 0;
}
by LZYAC @ 2024-05-23 22:17:15
求关注QwQ
by str2011 @ 2024-05-23 22:18:31
非常感谢(虽然我ac了,答案没什么用bushi)