84分救

P1104 生日

hexuchen @ 2023-07-10 10:26:12

#include <bits/stdc++.h>
using namespace std;
struct student{
    string name;
    int year,month,day;
};
bool cmp(student a,student b){
    if(a.year!=b.year)
        return a.year<b.year;
    if(a.month!=b.month)
        return a.month<b.month;
    if(a.day!=b.day)
        return a.day<b.day;
    return false;
}
int main(){
    int n;
    student s[101];
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>s[i].name>>s[i].year>>s[i].month>>s[i].day;
    }
    sort(s,s+n,cmp);
    for(int i=0;i<n;i++){
        cout<<s[i].name<<endl;
    }
    return 0;
}

m的最后一个点错了,但最后一个点90多个人...... 根本检查不了啊QAQ


by Henry2012 @ 2023-07-10 10:32:05

return false;

还要判断先后顺序


by Henry2012 @ 2023-07-10 10:32:49

如果有两个同学生日相同,输入靠后的同学先输出


by hexuchen @ 2023-07-10 10:38:04

@Henry2012 false就是靠后的人先输出啊


by Henry2012 @ 2023-07-10 11:00:46

排序的时候会把原来的顺序打乱,而且sort是不稳定的


by Henry2012 @ 2023-07-10 11:15:34

#include <bits/stdc++.h>
using namespace std; 
struct student{
    string name;
    int year,month,day,num;
};
bool cmp(student a,student b){
    if(a.year!=b.year)
        return a.year<b.year;
    if(a.month!=b.month)
        return a.month<b.month;
    if(a.day!=b.day)
        return a.day<b.day;
    return a.num>b.num; 
}
int main(){
    int n;
    student s[101];
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>s[i].name>>s[i].year>>s[i].month>>s[i].day,s[i].num=i;
    }
    sort(s,s+n,cmp);
    for(int i=0;i<n;i++){
        cout<<s[i].name<<endl;
    }
    return 0;
}

这样就AC了 @hexuchen


by Henry2012 @ 2023-07-10 11:15:50

求互关


by hexuchen @ 2023-07-11 08:38:27

@Henry2012 知道了,我真TM是个傻逼.......


|