King’s Heir
题意:
国王死了,他要把王位传给已满十八岁的最小的儿子,问应该传给谁。
思路:
水题……一开始脑子不清醒的我竟然WA了一次……
没啥好说的……
代码:
#include<bits/stdc++.h>
#define maxn 105
using namespace std;
struct son
{
int num,d,m,y;
}king,ss[maxn];
bool com(son a,son b)
{
if(a.y>b.y) return true;
else if(a.y==b.y&&a.m>b.m) return true;
else if(a.y==b.y&&a.m==b.m&&a.d>b.d) return true;
return false;
}
int main()
{
FILE *in,*out;
in=fopen("king.in","r");
out=fopen("king.out","w");
while(~fscanf(in,"%d%d%d",&king.d,&king.m,&king.y))
{
int n;
fscanf(in,"%d",&n);
for(int i=0;i<n;i++)
{
ss[i].num=i+1;
fscanf(in,"%d%d%d",&ss[i].d,&ss[i].m,&ss[i].y);
}
sort(ss,ss+n,com);
int res=-1;
for(int i=0;i<n;i++)
{
if((king.y-ss[i].y)*360+(king.m-ss[i].m)*30+king.d-ss[i].d>=18*360)
{
res=i;
break;
}
}
if(res==-1) fprintf(out,"-1\n");
else fprintf(out,"%d\n",ss[res].num);
}
fclose(in);fclose(out);
return 0;
}