Another date-manipulating problem :P
Task
Write a program or a function that calculates the difference between two dates given by a user.
Input & Output
Similar to the previous one, inputs are two YYYYMMDD
s, separated by a space , a comma
,
, or a minus sign -
.
Example of input values:
20100101-20010911
20110620-20121223
19000101 20101010
33330101,19960229
00010101 99991231
Output is an integer, which is difference between two dates, in days.
For example, input 20110101-20100101
yields 365
, and 33320229 17000101
yields 596124
.
You may test results at here at here. (See rintaun's comments below.) If two dates are same, the program should returns 0
, if the date is valid (see Score).
Restriction
Of course, you must not use any kinds of function/class/... which are related to timestamp or date, and you should use Gregorian calender.
Score
If your code doesn't keep the restriction, then score = -∞
.
Default bonus
is 1.
- If your code works regardless of order of inputs (for example,
20100101,20110101
returns365
or-365
),bonus+=1
. - If your code can handle year 0,
bonus+=0.5
. - If your code recognizes invalid month(between 1~12)/date(between 1~31), like
20109901
or34720132
, and printsE
(& terminates the program or returns something like0
),bonus+=1
. - Regardless of above rule, if your code recognizes invalid dates, like
20100230
,20100229
, or20111131
, and printsE
(& terminates the program or returns something like0
),bonus+=1
. - Regardless of above two rules, if your code recognizes invalid input string, like
20100101|20100202
or2010010120100202
, and printsE
(& terminates the program or returns something like0
),bonus+=1
.
score = floor(-4.2*code.length/bonus)
. Code with highest score wins. If two top codes have same score, then codes with highest bonus wins. If two top codes have both same score and bonus, then codes with highest votes wins.
(Due: When there's more than 5 codes which has more than (or equal) +1
votes.)
20040229
. :P \$\endgroup\$365*4 + 2 + 2
= 1464. Thanks for the information! \$\endgroup\$