Description
国王去世了,要选出其儿子中满 18 岁中最大的儿子当新的国王,给出国王去世日期和其 n 个儿子的出生日期,求新国王的编号
Input
第一行输入三个整数
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;
}