蓝桥杯备考(倒计时五十七天)——日期问题

http://lx.lanqiao.cn/problem.page?gpid=T2827icon-default.png?t=M0H8http://lx.lanqiao.cn/problem.page?gpid=T2827y总思路

#include

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

bool check(int year,int month,int day)
{
    if(month<=0||month>12) return false;
    if(day==0||month!=2&&day>days[month]) return false;
    if(month==2)
    {
        int leap=year%100&&year%4==0||year%400==0;

        if(day>28+leap) return false;
    }

    return true;
}

int main()
{
    int a,b,c;
    scanf("%d/%d/%d",&a,&b,&c);

    for(int i=19600101;i<=20591231;i++)
    {
        int year=i/10000,month=i%10000/100,day=i%100;

        if(check(year,month,day))
        {
           if(year%100==a&&month==b&&day==c||  //年/月/日
           year%100==c&&month==a&&day==b||  //月/日/年
           day==a&&month==b&&year%100==c    //日/月/年
           )
           printf("%d-%02d-%02d\n",year,month,day);
        }
    }

    return 0;
}

你可能感兴趣的:(蓝桥杯)