B. calendartime limit per test
2 seconds
Memory limit per test
256 megabytes
Input
Standard Input
Output
Standard output
Calendars in widespread use today include the Gregorian calendar, which is the de facto international standard, and is used almost everywhere in the world for civil purposes. the Gregorian Reform modified the Julian calendar's scheme of leap years as follows:
Every year that is exactly divisible by four is a leap year, week t for years that are exactly divisible by 100; The Centurial years that are exactly divisible by 400 are still leap years. For example,
The year 1900 is not a leap year; the year 2000 is a leap year.
In this problem, you have been given two dates and your task is to calculate how many days are between them. Note, that leap years have unusual number of days in February.
Look at the sample to understand what borders are stored in the aswer.
Input
The first two lines contain two dates, each date is in the format yyyy: mm: dd (1900 limit ≤ limitYyyyLimit ≤00002038 and yyyy: mm: dd is a legal date ).
Output
Print a single integer-the answer to the problem.
Sample test (s) Input
1900:01:012038:12:31
Output
50768
Input
1996:03:091991:11:12
Output
1579
PS: Thanks to Momo's solution report
Link: http://codeforces.com/problemset/problem/304/ B
For absolute questions, you can train your hands to Write Functions for judging dates. Some teams may be wa, but the subsequent date is not considered to be smaller than the previous date.
Question:
This question is very simple. If the question is given two dates, calculate the number of days between the two dates.
Solution:
The question says 1900 ≤ YY ≤ 2038, We can first create a reference date, 1900.1.1, then two days relative to this date, and then do the difference to find out. The format of the two strings to be read is fixed, and it is easy to process it into a date.
# Include <iostream> # include <cstdio> # include <cmath> # include <cstring> # include <string> # include <algorithm> # include <map> using namespace STD; int isrunyear (int yy) // determines whether the function is a year-Dependent Function {If (yy % 400 = 0) | (yy % 4 = 0 & YY % 100! = 0) return 1; else return 0;} int day [2] [12] = {31,28, 31,30, 31,30, 31,31, 30,31, 30,31}, {31,29,, 30, 31, 30, 31, 30, 31 }}; // two-dimensional array to store the number of days of each month in the year (int yy, int mm, int dd) // calculate the relative distance between the current date and 1900 days {int I; int sum = 0; for (I =; I <YY; I ++) {If (isrunyear (I) sum + = 366; else sum ++ = 365;} int P = isrunyear (yy); for (I = 1; I <mm; I ++) sum + = day [p] [I-1]; sum + = dd; return sum;} int main () {char a [11]; while (CIN> A) {int YY = (a [0]-'0') * 1000 + (A [1]-'0 ') * 100 + (A [2]-'0') * 10 + (A [3]-'0'); // string processing, processing year month day int Mm = (a [5]-'0') * 10 + (A [6]-'0 '); int dd = (a [8]-'0') * 10 + (A [9]-'0'); int Pa = calday (YY, mm, DD ); // The number of days from the first date. Cin> A; YY = (a [0]-'0') * 1000 + (A [1]-'0 ') * 100 + (A [2]-'0') * 10 + (A [3]-'0'); Mm = (a [5]-'0 ') * 10 + (A [6]-'0'); dd = (a [8]-'0') * 10 + (A [9]-'0 '); int Pb = calday (YY, mm, DD); // The number of days from the second date int res = ABS (Pa-PB ); // cout <res <Endl;} return 0;}/* 1900: 01: 012038: 12: 311996: 03: 091991: 11: 12 */