BirthNumbersValidator
SRM 333 · 2007-01-04 · by misof
Problem Statement
In Slovakia, every person is assigned a unique 10-digit string when he is born. This string is known as the birth number of the respective person.
The birth number has the form "YYMMDDCCCC", where:
- YY are the last two digits of the year.
- For males, MM is a two-digit number of the month, i.e., a number between 01 and 12, inclusive.
For females, MM is the number of the month increased by 50, i.e., a number between 51 and 62, inclusive. - DD is a two digit number of the day in the month.
- CCCC are four arbitrary digits that are used both as a checksum and as a way to distinguish between different people born on the same day.
The checksum property works as follows: the digits CCCC must be chosen in such a way that the entire 10-digit number is divisible by eleven (11).
For example, the strings "8104121234" and "8154121239" represent valid birth numbers.
(The first person is male, the second one female. Both of them are born on April 12th, ??81.)
The strings "8134120005", "8102310007", and "8104121235" are not valid birth numbers.
(In the first case, "34" can not be a valid month. In the second case, the day number is wrong, as the second month has less than 31 days. In the third case, the date is valid but the number is not divisible by 11.)
You will be given a
Notes
- The number of days in each month of a non-leap year (from 1 to 12): 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31.
- Leap years have 29 days in the second month.
- A year is a leap year if either (the year is divisible by 400) or (the year is divisible by 4, but not by 100). For example, 2000 and 2004 are leap years, 1900 and 1947 are not.
Constraints
- test will contain between 1 and 50 elements, inclusive.
- Each element of test will contain exactly 10 characters.
- Each element of test will contain only digits ('0'-'9').
{"8104121234"}
Returns: {"YES" }
The first example from the problem statement.
{"8154121239"}
Returns: {"YES" }
The second example from the problem statement.
{"8134120005"}
Returns: {"NO" }
The third example from the problem statement.
{"8102310007","8104121235"}
Returns: {"NO", "NO" }
The last two examples from the problem statement.
{"0411131237"}
Returns: {"YES" }
Note that leading zeros may occur in a valid birth number.
{"0702299389","0802290896","0902292787","1002296922","1102297801","1202298339","1302295390","1402290494","1502296653","1602291427","1702292372","1802290028","1902298695","2002290059","2102297769","2202293929","2302290540","2402293432","2502299173","2602295740","2702295211","2802295375","2902292569","3002296429","3102295790","3202291532","3302292862","3402295127","3502294070","3602293145","3702293936","3802299809","3902294022","4002293064","4102293074","4202298177","4302291400","4402298461","4502295017","4602298052","4702296236","4802297379","4902294430","5002294924","5102293790","5202298541","5302295207","5402294326","5502298318","5602294379"}
Returns: {"NO", "YES", "NO", "NO", "NO", "YES", "NO", "NO", "NO", "YES", "NO", "NO", "NO", "YES", "NO", "NO", "NO", "YES", "NO", "NO", "NO", "YES", "NO", "NO", "NO", "YES", "NO", "NO", "NO", "YES", "NO", "NO", "NO", "YES", "NO", "NO", "NO", "YES", "NO", "NO", "NO", "YES", "NO", "NO", "NO", "YES", "NO", "NO", "NO", "YES" }
leap years
{"5702296413","5802293530","5902296092","6002298984","6102299962","6202291876","6302296869","6402299178","6502296999","6602297284","6702292311","6802290935","6902297094","7002296334","7102290338","7202296508","7302290853","7402291732","7502291313","7602295866","7702296129","7802293895","7902299592","8002290549","8102298820","8202293374","8302295441","8402290369","8502294053","8602293755","8702291092","8802296811","8902297283","9002297183","9102295796","9202293584","9302295409","9402292658","9502292756","9602292403","9702299937","9802295063","9902299682","0002293368","0102297745","0202290022","0302296236","0402298589","0502298104","0602297542"}
Returns: {"NO", "NO", "NO", "YES", "NO", "NO", "NO", "YES", "NO", "NO", "NO", "YES", "NO", "NO", "NO", "YES", "NO", "NO", "NO", "YES", "NO", "NO", "NO", "YES", "NO", "NO", "NO", "YES", "NO", "NO", "NO", "YES", "NO", "NO", "NO", "YES", "NO", "NO", "NO", "YES", "NO", "NO", "NO", "YES", "NO", "NO", "NO", "YES", "NO", "NO" }
leap years
{"0752299383","0852290890","0952292781","1052296916","1152297795","1252298344","1352295395","1452290499","1552296658","1652291421","1752292366","1852290033","1952298700","2052290064","2152297763","2252293934","2352290545","2452293426","2552299178","2652295745","2752295216","2852295369","2952292574","3052296434","3152295784","3252291537","3352292867","3452295132","3552294075","3652293139","3752293930","3852299803","3952294027","4052293058","4152293079","4252298171","4352291394","4452298466","4552295011","4652298046","4752296230","4852297373","4952294424","5052294929","5152293784","5252298546","5352295201","5452294331","5552298323","5652294373"}
Returns: {"NO", "YES", "NO", "NO", "NO", "YES", "NO", "NO", "NO", "YES", "NO", "NO", "NO", "YES", "NO", "NO", "NO", "YES", "NO", "NO", "NO", "YES", "NO", "NO", "NO", "YES", "NO", "NO", "NO", "YES", "NO", "NO", "NO", "YES", "NO", "NO", "NO", "YES", "NO", "NO", "NO", "YES", "NO", "NO", "NO", "YES", "NO", "NO", "NO", "YES" }
leap years
{"5752296418","5852293535","5952296097","6052298989","6152299956","6252291881","6352296863","6452299172","6552297004","6652297289","6752292305","6852290929","6952297088","7052296328","7152290343","7252296513","7352290847","7452291737","7552291318","7652295860","7752296134","7852293900","7952299586","8052290554","8152298814","8252293368","8352295435","8452290374","8552294047","8652293760","8752291097","8852296816","8952297277","9052297188","9152295790","9252293589","9352295403","9452292652","9552292761","9652292408","9752299942","9852295068","9952299676","0052293373","0152297739","0252290016","0352296230","0452298594","0552298098","0652297547"}
Returns: {"NO", "NO", "NO", "YES", "NO", "NO", "NO", "YES", "NO", "NO", "NO", "YES", "NO", "NO", "NO", "YES", "NO", "NO", "NO", "YES", "NO", "NO", "NO", "YES", "NO", "NO", "NO", "YES", "NO", "NO", "NO", "YES", "NO", "NO", "NO", "YES", "NO", "NO", "NO", "YES", "NO", "NO", "NO", "YES", "NO", "NO", "NO", "YES", "NO", "NO" }
leap years
{"8110001240", "8100041290", "0004111294", "0000000000", "8160001234", "8100051234", "0054121232", "0050000005"}
Returns: {"NO", "NO", "YES", "NO", "NO", "NO", "YES", "NO" }
zero day, month, year
{"8102298765","8002298766"}
Returns: {"NO", "YES" }
The year 1981 was not a leap year, and thus there was no 29th February in 1981. The year 1980 was a leap year and thus the second element is a valid birth number.
Submissions are judged against all 172 archived test cases, of which 11 are shown here. Case numbers match the judge’s.
Language: C++17 · define a public class BirthNumbersValidator with a public method vector<string> validate(vector<string> test) · 172 test cases · 2 s / 256 MB per case