问题标题: 酷町堂:1422

0
0
已解决
胡钰妍
胡钰妍
资深光能
资深光能

#include <bits/stdc++.h>

using namespace std;

int a,b,count1;

int fj1[10];

int y[13]={0,31,0,31,30,31,30,31,31,30,31,30,31};

void pd(int n)

{

    if (n%4==0&&n%100!=0||n%400==0)

        y[2]=29;

    else y[2]=28;

    return ;

}

void fj(int n)

{

    int i=0;

    while (n)

    {

        fj1[++i]=n%10;

        n/=10;

    }

}

bool hw()

{

    int l=1,r=8;

    while (l<=r)

    {

        if (fj1[l]!=fj1[r])

            return 0;

        l++,r--;

    }

    return 1;

}

int main ()

{

    cin>>a>>b;

    int n1=a/10000,n2=b/10000;

    int y1=(a%10000)/100,y2=(b%10000)/100;

    int r1=a%100,r2=b%100;

    for (int i=n1;i<=n2;i++)

    {

        pd(i);

        int cmp1,h1;

        if (i==n1) cmp1=y1;

        else cmp1=1;

        if (i==n2) h1=y2;

        else h1=12;

        for (int j=cmp1;j<=h1;j++)

        {

            int cmp2,h2;

            if (i==n1) cmp2=r1;

            else cmp2=1;

            if (i==n2&&j==y2) h2=r2;

            else h2=y[j];

            for (int k=cmp2;k<=h2;k++)

            {

                int ans1=i;

                ans1=ans1*100+j;

                ans1=ans1*100+k;

                fj(ans1);

                if (hw())

                    count1++;

            }

        }

    }

    cout<<count1;

    return 0;

}

哪错了


0
已采纳
张帆
张帆
中级天翼
中级天翼

你的代码很感人(我看不懂)

建议用我这种思路(19行)

仔细分析日期可得,一年中最多只有一次回文日期,

1st:输入,将年月日分离出来

2nd:枚举开始年到结束年

3rd:判断此年的回文日期是否和发,合法就cnt加一

      需判断以下二条

      1.

本日期是否合法
月>=1&&月<=12
天>=1&&天<=y[月](年如果是闰年,y[2]=29,否则y[2]=28)

      2.

设本日期8位数为c
a<=c&&b>=c

4th:输出cnt

 

我要回答