Time
Time limit1sMemory limit128 MB
Given two valid dates and a period such as 3 months or 2 days, count how many whole periods aligned to unit boundaries fit between them using Gregorian leap year rules.
- Level
Medium7 of 10
- Topics
- Math, Implementation, Simulation, Binary search
- Solved
- No attempts yet
Problem
A time point is given as six integers standing for year, month, day, hour, minute, and second, with , , , , , and .
Write a program that computes how many periods of a given length fit between two given time points. A period is given by a pair consisting of a positive integer and a word naming a time unit, one of year, month, day, hour, minute, or second.
Every 4th year is a leap year, except every 100th year, which is not, except every 400th year, which is. The length of a year varies according to leap years, and so does the length of February.
Time units always start as usual: a year starts on January 1st, a month starts on its 1st day, a day starts at 0 hours 0 minutes 0 seconds, and so on. A period ends after its last second. Hence you must report the maximum number of non-overlapping periods that fit exactly on these unit boundaries between the two time points.
Input
The input consists of blocks of lines. Each block has three lines. The first line of a block contains a time point and the second line a time point ; always precedes . All numbers on a line are separated by one space. You may assume that every given time point is valid. The third line contains a time period, with exactly one space between the number and the word. After each block there is one empty line.
Output
Output one line for each block of the input. The line corresponding to a block contains a single integer telling how many of the specified periods are contained between the two given time points.