蒟蒻求教,接受各种风格

P2010 [NOIP2016 普及组] 回文日期

4kilometers @ 2016-12-17 18:02:52

#include<cstdio>
#include<cstring>
using namespace std;
bool rn (int n);
int year (int n);
int month (int n);
int date (int n);
bool check (int n);
int date1,date2,tot=0;
int main()
{
    scanf("%d%d",&date1,&date2);
    for (int i=date1;i<=date2;++i)
    {
        int y=year(i),m=month(i),d=date(i);
        if (m>12||m<1) continue;
        if (d>31||d<1) continue;
        if (m==2)
        {
            if (rn(i)==false)
            {
                if (m==2&&d>28) continue;
            }
            if (rn(i)==true)
            {
                if (m==2&&d>29) continue;
            }
        }
        if (m==4||m==6||m==9||m==11)
        {
            if (d==31) continue;
        }
        if (check(i)==true)
         ++tot;
    }
    printf("%d",tot);
    return 0;
}
bool rn (int n)
{
    if (year(n)%4==0&&year(n)%100!=0) return true;
    else if (year(n)%400==0) return true;
    else return false;
}
int year (int n)
{
    return n/10000;
}
int month (int n)
{
    return (n-year(n)*10000)/100;
}
int date (int n)
{
    return n%100;
}
bool check (int n)
{
    char s[9];
    int temp=0;
    sprintf(s,"%d",n);
    for (int i=0;i<=3;++i)
    {
        if (s[i]==s[7-i]) temp++;
    }
    if (temp==4) return true;
    else return false;
}

愚蠢暴力,见笑啦。 洛谷80,Noip初评70


by 陆远哲 @ 2016-12-17 19:46:26

什么问题?


by txyx @ 2016-12-19 19:39:16

直接枚举年份就可以了啊


by Alextokc @ 2017-03-15 15:36:19

直接枚举年份啊。。


|