codeup 1928: 日期差值,答案错误,我看书上也差不多是这样写,为什么就是通不过

时间限制: 1 Sec 内存限制: 32 MB
题目描述
有两个日期,求两个日期之间的天数,如果两个日期是连续的我们规定他们之间的天数为两天。

输入
有多组数据,每组数据有两行,分别表示两个日期,形式为YYYYMMDD

输出
每组数据输出一行,即日期差值

样例输入
20130101
20130105
样例输出
5
来源

#include <iostream>

using std::cin;
using std::cout;
using std::endl;

int isLeap(int year);

int month[13][2] = {{0,0},{31,31},{28,29},{31,31},{30,30},{31,31},{30,30},{31,31},{31,31},{30,30},{31,31},{30,30},{31,31}} ;


int main(){

    int temp,sel,date1,date2,days = 1;
    int year1,year2,months1,months2,day1,day2;
    while(cin >> date1 && cin >> date2){
        if(date1 > date2){
            temp = date1;
            date1 = date2;
            date2 = temp;
        }
        year1 = date1 / 10000;
        year2 = date2 / 10000;
        months1 = (date1 / 100) % 100;
        months2 = (date2 / 100) % 100;
        day1 = date1 % 100;
        day2 = date2 % 100;

        sel = isLeap(year1);
        while(year1 < year2 || months1 < months2 || day1 < day2){
            day1++;
            days++;
            if(day1 == month[months1][sel] + 1 ){
                day1 = 1;
                months1++;
            }
            if(months1 == 13){
                months1 = 1;
                year1++;
                sel = isLeap(year1);
            }
        }
        cout << days << endl;   
    }
    return 0;
}

int isLeap(int year){
    return (year % 4 == 0 )&&(year % 100 != 0)||(year % 400 == 0);
}

闰年的判断方法不对,正确判断是否为闰年的表达式应为:(year % 4 == 0 )&&(year % 100 != 0)||(year % 400 == 0)

抱歉,之前回答时没有看到回复,但由于无法删除评论所以只能这样了。