55分,经调试样例没有发现问题,求大佬帮助,谢谢。

P2010 [NOIP2016 普及组] 回文日期

Oven_PtP @ 2022-02-02 12:57:09

#include<iostream>
using namespace std;
int main()
{
    int date1,date2;
    int year1,month1,day1,sum_days=0,sum_1=0,a1;
    int i,j;
    cin>>date1>>date2;
    year1=date1/10000;
    month1=date1/100-year1*100;
    day1=date1-date1/100*100;
    i=date1,j=date2;
    while(i<j)
    {
        a1=i;
        while(a1)
        {
            sum_1=sum_1*10+a1%10;
            a1/=10;
        }
        if(sum_1==i)
        sum_days++;
        sum_1=0;
        if(year1%4==0&&year1%100!=0||year1%400==0)
        {
            if(month1==1||month1==3||month1==5||month1==7||month1==8||month1==10||month1==12)
            {
                if(month1==12)
                {
                    if(day1==31)
                    {
                        year1++;
                        month1=1;
                        day1=1;
                        i=i+10000-1100-30;
                    }
                    else
                    {
                        day1++;
                        i++;
                    }
                }
                else
                if(day1==31)
                {
                    i=i-30+100;
                    day1=1;
                    month1++;
                }
                else
                {
                    day1++;
                    i++;
                }
            }
            if(month1==4||month1==6||month1==9||month1==11)
            {
                if(day1==30)
                {
                    i=i-29+100;
                    day1=1;
                    month1++;
                }
                else
                {
                    day1++;
                    i++;
                }
            }
            if(month1==2)
            {
                if(day1==29)
                {
                    i=i-28+100;
                    day1=1;
                    month1++;
                }
                else
                {
                    day1++;
                    i++;
                }
            }
        }
        else
        {
            if(month1==1||month1==3||month1==5||month1==7||month1==8||month1==10||month1==12)
            {
                if(month1==12)
                {
                    if(day1==31)
                    {
                        year1++;
                        month1=1;
                        day1=1;
                        i=i+10000-1100-30;
                    }
                    else
                    {
                        day1++;
                        i++;
                    }
                }
                else
                if(day1==31)
                {
                    i=i-30+100;
                    day1=1;
                    month1++;
                }
                else
                {
                    day1++;
                    i++;
                }
            }
            if(month1==4||month1==6||month1==9||month1==11)
            {
                if(day1==30)
                {
                    i=i-29+100;
                    day1=1;
                    month1++;
                }
                else
                {
                    day1++;
                    i++;
                }
            }
            if(month1==2)
            {
                if(day1==28)
                {
                    i=i-27+100;
                    day1=1;
                    month1++;
                }
                else
                {
                    day1++;
                    i++;
                }
            }
        }
    }
    cout<<sum_days<<endl;
    return 0;
}

|