#include<iostream>
#include<cstdio>
#include<cassert>
using namespace std;
int d1, d2;
int ans;
int days[] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
bool rn(int y)
{
    return y % 400 == 0 || (y % 4 == 0 && y % 100 != 0 );
}
bool check(int y, int m, int d)
{
    if(m == 2 && d == 29)
    {
        return rn(y);
    }
    if(m >= 1 && m <= 12)
    {
        return days[m] >= d && d > 0;
    }
    else
        return 0;
}
void getMD(int curY, int &m, int &d)
{
    int a1, a2, a3, a4;
    a1= curY % 10;
    curY /= 10;
    a2 =  curY % 10; curY /= 10;
    a3 = curY % 10; curY /= 10;
    a4 = curY;
    //m = a4 * 10 + a3;
    //d = a2 * 10 + a1;
    d = a3 * 10 + a4;
    m = a1 * 10 + a2;
}
void handle()
{
    //枚举年份,通过年份得到月和日,再check月和日是否合法
    int startY = d1 /10000;
    int endY = d2 / 10000;
    for(int i = startY; i <= endY; i++)
    {
        // get month
        int m ,d;
        getMD(i, m, d);
        if(check(i, m, d))
        {
            int curDate = i * 10000 + m * 100 + d;
            if(curDate >= d1 && curDate <= d2)
            {
                ans++;
            }
        }
    }
    cout << ans << endl;
}
void checkMD();
int main(void)
{
   cin >> d1 >> d2;
   handle();
  // checkMD();
    return 0;
}
void checkMD()
{
    int m, d;
    getMD(1234, m, d);
    assert(m==43 && d== 21);
    getMD(1122,m, d);
    assert(m==22 && d== 11);
    cout << "getMD is OK" << endl;
}

0 条评论

目前还没有评论...

信息

ID
183
时间
1000ms
内存
256MiB
难度
7
标签
递交数
276
已通过
66
上传者
}