计蒜客————King's Heir

  •  56.93%
  •  2000ms
  •  262144K


The king is dead, long live the king! After the sudden death of the king Fert XIII the people of theFlatland Kingdom are going to welcome the new king. Unfortunately, there is a problem, Fert has too many sons.

Actually, he has sons and he loved each new son more than all of his previous sons. Well, probably he just stopped loving his sons because of their bad behavior. Anyway, after the new son was born Fert made the new testament that declared that the newly born son would be the heir.

However, there is a problem. Only the king’s son who is at least 18 years old at the moment of the king’s death can become a new king. Now the ministers of the government are trying to find the correct new king, but they seem to fail. Help them!

Input

The first line of the input contains three integers: d,and — the day, the month and the year of the king’s death, is from 1 to 31, is from 1 to 12,is from 1 to 9999. It is guaranteed that there exists day in month m, all months have the same number of days in Flatland as in our country, except thatFlatland calendar doesn’t have leap years, so February (month 2) always has 28 days.

The second line contains (1 ≤ ≤ 100) — the number of king’s sons. The following lines contain three integers each dimand yand specify the birth dates of king’s sons. All dates are correct and no son is born after or on the day of king’s death. The king had no twins, so no two sons were born on the same date.

Output

Output one integer — the number of the son that would become the king, or 1 if none of them is at least 18 years old. The sons are numbered from 1 to in order they are described in the input. The youngest son who is at least 18 years old at the moment of the king’s death would become the king. If the son has his 18th birthday exactly on the day of the king’s death, he can become a king. 

样例输入1
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
样例输出1
3
样例输入2
22 10 2016
1
28 2 1999
样例输出2
-1
给出国王的死亡日期,找出最年轻的大于等于18的王子。
#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
#define trans(x,y,z) z+0.01*y+0.0001*x
int main(){
    int x,y,z;
    while(~scanf("%d%d%d",&x,&y,&z)){
        double X=trans(x,y,z),val=99999;
        int n,flag=-1;
        scanf("%d",&n);
        for(int i=1;i<=n;i++){
            scanf("%d%d%d",&x,&y,&z);
            double t=trans(x,y,z);
            if(X-t>=18.0&&X-t<val){
                flag=i;
                val=X-t;
            }
        }
        printf("%d\n",flag);
    }
    return 0;
}
[{ "resource": "/E:/CMake/share/cmake-3.25/Modules/CMakeTestCXXCompiler.cmake", "owner": "cmake-configure-diags", "severity": 8, "message": "CMake Error at E:/CMake/share/cmake-3.25/Modules/CMakeTestCXXCompiler.cmake:63 (message):The C++ compiler\n\n \"E:/Qt/Qt5.12.12/Tools/mingw730_64/bin/g++.exe\"\n\nis not able to compile a simple test program.\n\nIt fails with the following output:\n\n Change Dir: F:/Project/Qt/vscode_demo/build/CMakeFiles/CMakeScratch/TryCompile-heir70\n \n Run Build Command(s):E:/Qt/Qt5.12.12/Tools/mingw730_64/bin/mingw32-make.exe -f Makefile cmTC_52656/fast && E:/Qt/Qt5.12.12/Tools/mingw730_64/bin/mingw32-make.exe -f CMakeFiles\\cmTC_52656.dir\\build.make CMakeFiles/cmTC_52656.dir/build\n mingw32-make.exe[1]: Entering directory 'F:/Project/Qt/vscode_demo/build/CMakeFiles/CMakeScratch/TryCompile-heir70'\n Building CXX object CMakeFiles/cmTC_52656.dir/testCXXCompiler.cxx.obj\n E:\\Qt\\Qt5.12.12\\Tools\\mingw730_64\\bin\\g++.exe -o CMakeFiles\\cmTC_52656.dir\\testCXXCompiler.cxx.obj -c F:\\Project\\Qt\\vscode_demo\\build\\CMakeFiles\\CMakeScratch\\TryCompile-heir70\\testCXXCompiler.cxx\n mingw32-make.exe[1]: *** [CMakeFiles\\cmTC_52656.dir\\build.make:77: CMakeFiles/cmTC_52656.dir/testCXXCompiler.cxx.obj] Error 1\n mingw32-make.exe[1]: Leaving directory 'F:/Project/Qt/vscode_demo/build/CMakeFiles/CMakeScratch/TryCompile-heir70'\n mingw32-make.exe: *** [Makefile:126: cmTC_52656/fast] Error 2\n \n \n\n\n\nCMake will not be able to correctly generate this project.", "source": "CMake (message)", "startLineNumber": 63, "startColumn": 1, "endLineNumber": 63, "endColumn": 10000, "relatedInformation": [ { "startLineNumber": 2, "startColumn": 1, "endLineNumber": 2, "endColumn": 1000, "message": "In call to 'project' here", "resource": "/F:/Project/Qt/vscode_demo/CMakeLists.txt" } ] }]
最新发布
06-12
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值