P1104 生日 洛谷(结构体排序)

简单的结构体排序,可是最后一组样例总是通不过?看了别人的题解才知道原来编号也得算进排序…题目里面还告诉了…结果WA了几次…果然这是没认真读题的后果…生日从大到小的意味着年份小,相同年分比月份小,相同月份比天数小,相同天数比编号大…代码如下:

#include <cstdio>
#include <iostream>
#include <algorithm>
#include <string>
#include <cstring>
#include <cmath>
#include <stack>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <utility>
#define ll long long

using namespace std ;

typedef struct{
    string name ;
    int year ;
    int month ;
    int day ;
    int number ;
}meassage ;

bool cmp(meassage x , meassage y){
    if ( x.year == y.year ){
        if ( x.month == y.month ){
            if ( x.day == y.day ){
                return x.number > y.number ;
            }
            return x.day < y.day ;
        }
        return x.month < y.month ;
    }
    return x.year < y.year ;
}

int main(){
    meassage mea[500] ;
    int n ;
    cin >> n ;
    for ( int i = 0 ; i < n ; i ++ ){
        cin >> mea[i].name >> mea[i].year >> mea[i].month >> mea[i].day ;
        mea[i].number = i ;
    }
    sort(mea , mea + n , cmp) ;
    for ( int i = 0 ; i < n ; i ++ ){
        if ( i == n - 1 ){
            cout << mea[i].name ;
        }else{
            cout << mea[i].name << endl ;
        }
    }
    return 0 ;
}

转载于:https://www.cnblogs.com/Cantredo/p/9775417.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值