using namespace std;
Bool isLeap (int x)
{
If (x % 4==0 & amp; & ! (x % 400!=0 & amp; & X % 100==0))
{
return true;
}
The else
return false;
}
Int the month [13]={0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
Int main () {
Int startYear, startMonth startDay;
Int endYear, endMonth, endDay;
cout<" Please enter the correct the beginning of the year, month, day, with a blank key intermediate: ";
Cin & gt;> StartYear & gt;> StartMonth & gt;> StartDay;
cout<" Please input the right end of the year, month, day, with a blank key intermediate: ";
Cin & gt;> EndYear & gt;> EndMonth & gt;> EndDay;
Int ans=0;
If (startYear==endYear)//if it is in the same year
{
If (startMonth==endMonth)
{
Ans=endDay - startDay;
}
The else
{
For (int I=startMonth + 1; i
Ans +=month [I];
}
Ans +=month [startMonth] - startDay + endDay;
If (isLeap (startYear))//if it is a leap year
{
If (startMonth & lt;=2 & amp; & EndMonth & gt; 2)//whether start-stop month contains 2 month
{
Ans +=1;
}
}
}
}
The else
{
//calculation between two year year the total number of days of
For (int I=startYear + 1; i
Ans +=365;
If (isLeap (I))
Ans +=1;
}
//calculation of total number of days starting year
For (int I=startMonth + 1; i <=12; I + +)
{
Ans +=month [I];
}
Ans +=month [startMonth] - startDay;
//special judge if the month starting in February before February (including), in the case of leap year, the number of days to add 1
If (isLeap (startYear))
{
If (startMonth & lt;
=2){
Ans +=1;
}
}
//calculate end of days
For (int I=1; i
Ans +=month [I];
}
Ans +=endDay;
//special judge if the month end in February after February (not including), in the case of leap year, the number of days to add 1
If (isLeap (endYear))
{
If (endMonth & gt; 2)
{
Ans +=1;
}
}
}
cout
return 0;
}
CodePudding user response:
In order to cycle starting from 1For (int I=1; i
CodePudding user response:
In this way, and in the subscript is consistent, it is not easy to confuse