GYM 101142 K.King’s Heir(水~)

253 篇文章 2 订阅

Description

国王去世了,要选出其儿子中满 18 岁中最大的儿子当新的国王,给出国王去世日期和其 n 个儿子的出生日期,求新国王的编号

Input

第一行输入三个整数D,M,Y表示国王在 Y M D 日去世的,之后输入一整数n表示国王儿子数量,之后 n 行每行输入三个整数di,mi,yi表示第 i 个儿子是di mi di 日出生的 (1D,di31,1M,mi12,1Y,yi9999,1n100) ,每年二月都是 28 天,没有两个儿子是同一天生的

Output

输出当新国王的儿子编号,如果没有满足条件的儿子则输出 1

Sample Input

22 10 2016
7
28 2 1999
22 7 1995
21 10 1998
23 10 1998
3 9 2000
1 4 2013
17 12 2004

Sample Output

3

Solution

简单题,把年满十八周岁的儿子拿出来排个序即可

Code

#include<cstdio>
#include<iostream>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<ctime>
using namespace std;
typedef long long ll;
typedef pair<int,int>P;
const int INF=0x3f3f3f3f,maxn=105;
struct node
{
    int d,m,y,id;
    bool operator<(const node &b)const
    {
        if(y!=b.y)return y>b.y;
        if(m!=b.m)return m>b.m;
        return d>b.d;
    }
}a[maxn],b,c;
int n;
int main()
{
    freopen("king.in","r",stdin);
    freopen("king.out","w",stdout);
    while(~scanf("%d%d%d",&b.d,&b.m,&b.y))
    {
        scanf("%d",&n);
        int m=0;
        for(int i=1;i<=n;i++)
        {
            scanf("%d%d%d",&c.d,&c.m,&c.y);
            c.id=i;
            if(b.y-c.y>18||b.y-c.y==18&&(b.m>c.m||b.m==c.m&&b.d>=c.d))a[m++]=c;
        }
        if(m==0)printf("-1\n");
        else 
        {
            sort(a,a+m);
            printf("%d\n",a[0].id);
        }
    }
    return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值