A - AD 2020

2020 is the current year and is a leap year starting on Wednesday of the Gregorian calendar, the 2020th year of the Common Era (CE) and Anno Domini (AD) designations, the 20th year of the 3rd millennium, the 20th year of the 21st century, and the 1st year of the 2020s decade.

2020 has been designated as Year of the Nurse and Midwife by the World Health Organization. The United Nations has declared 2020 as the International Year of Plant Health. 2020 has been designated as International Year of Sound by the International Commission for Acoustics.

Because there are so many unforgettable things happening in 2020, somebody has now proposed that all dates with a substring containing "202" to be designated as the Day for Disaster Reduction. We represent a date in the format YYYYMMDD (for example, 21110202), then if 202 is a substring of this date, this day is the Day for Disaster Reduction.

Please write a program to compute how many Days for Disaster Reduction are there in all the dates between Y_1Y1​M_1M1​D_1D1​ and Y_2Y2​M_2M2​D_2D2​ (both inclusive)? Note that you should take leap years into consideration. A leap year is a year that can be divided by 400 or can be divided by 4 but can't be divided by 100. A leap year has 2929 days in February, instead of the normal 2828 days.

Input

The input contains multiple cases. The first line of the input contains a single positive integer TT (1 \le T \le 10^51≤T≤105), the number of cases.

The first and only line of each case contains six integers Y_1,M_1,D_1,Y_2,M_2,D_2Y1​,M1​,D1​,Y2​,M2​,D2​, which are described in the problem statement above.

It's guaranteed that Y_1Y1​M_1M1​D_1D1​ is not larger than Y_2Y2​M_2M2​D_2D2​. Both Y_1Y1​M_1M1​D_1D1​ and Y_2Y2​M_2M2​D_2D2​ are between 20000101 and 99991231, and both dates are valid.

We kindly remind you that the size of the input and output of this problem can be large, so it's recommended to use a faster I/O method. For example, in C++, you can use scanf/printf instead of cin/cout.

Output

For each case, print a single line containing a single integer, the answer.

#include <bits/stdc++.h>

using namespace std;

int pre[10000][12][40];
int month[] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
inline bool is_run(int year) 
{
    if (year % 400 == 0) return true;
    if (year % 100 != 0 && year % 4 == 0) return true;
    return false;
}
inline bool is_202(int num) 
{
    string str = "";
    bool flag1 = false;
    bool flag2 = false;
    while (num)
    {
        int temp = num % 10;
        if (temp == 2) flag1 = true;
        if (temp == 0) flag2 = true;
        num /= 10;
        str += (temp + '0');
    }
    if (!flag1 || !flag2) return false;
    for (int i = 0; i < str.size(); i++) 
    {
        if (i + 3 - 1 <= str.size() - 1) 
        {
            if (str.substr(i, 3) == "202") return true;
        }
    }
    return false;
}
signed main() 
{
    int T;
    int yea = 2000, mon = 1, da = 1;
    int ans = 0;
    while (true) 
    {
        int num = yea * 10000 + mon * 100 + da;
        if (is_202(num)) ans++;
        pre[yea][mon][da] = ans;
        if (yea == 9999 && mon == 12 && da == 31) 
            break;
        if (is_run(yea))
            month[2] = 29;
        else
            month[2] = 28;
        if (da + 1 <= month[mon]) 
        {
            da += 1;
        } 
        else if (mon + 1 <= 12) 
        {
            da = 1;
            mon += 1;
        } 
        else 
        {
            da = 1;
            mon = 1;
            yea++;
        }
    }
    scanf("%lld", &T);
    while (T--) 
    {
        int year1, month1, day1, year2, month2, day2;
        scanf("%lld%lld%lld%lld%lld%lld", &year1, &month1, &day1, &year2,&month2, &day2);
        int ans = pre[year2][month2][day2] - pre[year1][month1][day1];
        if (is_202(year1 * 10000 + month1 * 100 + day1)) ans++;
        printf("%lld\n", ans);
    }
    return 0;
}

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值