# 252: given two dates, the calculation is the number of days, such as the 2010-1-1 and 2010-1-1 by 2 day,
Time limit: 2 SEC. Memory limit: 128 MB.
Item description
Given two date, calculated by the number of days, such as the 2010-1-1 and 2010-1-1 by 2 day,
Input format
A total of two lines: the first line contains three integers startYear, startMonth, startDay, respectively is the starting year, month, day, the second line contains three integers endYear, endMonth, endDay, respectively is the end of the year, month, day, between the adjacent two integers separated by a single space, the range between 1 ~ 3000 year, ensure correct date and end date is not earlier than start date,
The output format
Output an integer, which is two dates vary the number of days,
The sample input
2008 1 1
2009 1 1
Sample output
366
Date expressed in (date) (month) (year), expressed as a number of days between the,
Considering the leap year between the date,
Here is my code only 8 points really can not find the bug where I'm going crazy
#include
Struct date/date/definition structure
{
Int year;
Int the month;
Int day;
};
Int main ()
{
During the int isLeap (int);//is a leap year function, it is a leap year return 1, leap year returns 0
Long dayBetween (struct date fromDate, struct date toDate);//computing function of the number of days between two dates
Struct date fromDate, toDate;
The scanf (" % d % d % d % d % d % d ", & amp; FromDate. Year, & amp; FromDate month, & amp; FromDate. Day, & amp; ToDate. Year, & amp; ToDate. The month, & amp; ToDate. Day);
Printf (" % ld, "dayBetween (fromDate, toDate));
}
During the int isLeap (int)
{
If ((year % 4==0 & amp; & Year % 100!=0) | | year %==0 400)
{
return 1;
}
The else
return 0;
}
Long dayBetween (struct date fromDate, struct date toDate)
{
//number of days between the two date=annual difference between the * 365 or 366 - start in the old days + end in the old days
Int I, count=0, day=0, day1=0, day2=0;
For (I=fromDate. Year; i
If (isLeap (I)==1)
{
The count=count + 366;
}
The else
The count=count + 365;
}
Int d [2] [13]={{0,31,28,31,30,31,30,31,31,30,31,30,31},
,31,29,31,30,31,30,31,31,30,31,30,31 {0}
};//d [1] for leap years, d [0] for common year
for(i=1; i
Day1=day1 + d [isLeap (fromDate. Year)] [I];
}
Day1=day1 + fromDate. Day;
for(i=1; i
Day2=day2 + d [isLeap (fromDate. Year)] [I];
}
Day2=day2 + toDate. Day;
Day=count - day1 + day2;
The return day.
}
/* test data:
1 1 1
3000 12 31
1095726
12 12 2017
2018 2 26
76
28 2000 2
2000 3 1
2
*/
CodePudding user response:
Autumn cream bosses face and have a lookCodePudding user response:
End this post I willCodePudding user response:
I hope it can help you: https://blog.csdn.net/it_xiangqiang/category_10581430.htmlI hope it can help you: https://blog.csdn.net/it_xiangqiang/category_10768339.html