80WA,玄关

P1104 生日

LNYZY @ 2024-10-24 21:13:16

80分链接

#include<bits/stdc++.h>
using namespace std;
struct t{
    int y,m,d,lj;
    string student_name;
}a[105];
bool cmp(t a,t b){
    if(a.y!=b.y){
        return a.y<b.y;
    }
    else{
        if(a.m!=b.m){
            return a.m<b.m;
        }
        else if(a.d==b.d and a.m==b.m){
            return a.lj>b.lj;
        }
        else{
            return a.d<b.d;
        }
    }
}
int main(){
    int n;
    cin>>n;
    for(int i=1;i<=n;i++){
        cin>>a[i].student_name>>a[i].y>>a[i].m>>a[i].d;
    }
    sort(a+1,a+n+1,cmp);
    for(int i=1;i<=n;i++){
        cout<<a[i].student_name<<endl;
    }
    return 0;
}

by Ybll_ @ 2024-10-24 21:16:38

#include<bits/stdc++.h>
using namespace std;
struct t{
    int y,m,d,lj;
    string student_name;
}a[105];
bool cmp(t a,t b){
    if(a.y!=b.y){
        return a.y<b.y;
    }
    else{
        if(a.m!=b.m){
            return a.m<b.m;
        }
        else if(a.d==b.d and a.m==b.m){
            return a.lj>b.lj;
        }
        else{
            if(a.d!=b.d)return a.d<b.d;
            else return a.lj>b.lj;
        }
    }
}
int main(){
    int n;
    cin>>n;
    for(int i=1;i<=n;i++){
        cin>>a[i].student_name>>a[i].y>>a[i].m>>a[i].d;
        a[i].lj=i; 
    }
    sort(a+1,a+n+1,cmp);
    for(int i=1;i<=n;i++){
        cout<<a[i].student_name<<endl;
    }
    return 0;
}

by Ybll_ @ 2024-10-24 21:17:26

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


by Wang_Xu @ 2024-10-24 21:18:29

struct shengri
{
    string name;
    int n,m,d,sum;
}a[110];
bool cmp(shengri a,shengri b)
{
    if(a.n<b.n)
    {
        return 1;
    }
    if(a.n>b.n)
    {
        return 0;
    }
    if(a.n==b.n)
    {
        if(a.m<b.m)
        {
            return 1;
        }
        if(a.m>b.m)
        {
            return 0;
        }
        if(a.m==b.m)
        {
            if(a.d<b.d)
            {
                return 1;
            }
            if(a.d>b.d)
            {
                return 0;
            }
            if(a.d==b.d)
            {
                if(a.sum>b.sum)
                {
                    return 1;
                }
                else 
                {
                    return 0;
                }
            }
        }
    }
}

@LNYZY 这是我结构体和cmp,可以参考下


by LNYZY @ 2024-10-24 21:23:39

@Wang_Xu @Ybll_ 已关


by Ybll_ @ 2024-10-24 21:27:22

@LNYZY 谢谢


by qujunhao @ 2024-10-24 21:33:40

#include <bits/stdc++.h>
using namespace std;
struct note{
    string s;
    int y, m, d, num;
}f[100];
bool cmp ( note a, note b ){
    if ( a.y == b.y ){
        if ( a.m == b.m ){
            if ( a.d == b.d ) return a.num > b.num;
            else return a.d < b.d;
        }
        else return a.m < b.m;
    }
    else return a.y < b.y;
}
int n;
int main(){
    scanf ( "%d", &n );
    for ( int i = 1; i <= n; i++ )
    cin >> f[i].s >> f[i].y >> f[i].m >> f[i].d, f[i].num = i;
    sort ( f+1, f+n+1, cmp );
    for ( int i = 1; i <= n; i++ )
    cout << f[i].s << endl;
        return 0;
}

求关


|