zoukankan      html  css  js  c++  java
  • date题解

    这道题有两种做法,一是直接暴力枚举天数(居然没炸!!!???)而是我们可以发现,一年中最多只有一天可以形成回文日期。那么,我们只需要枚举年份,然后再判断所对应的月,日是否符合逻辑,和规定日期然后就可以了

    ----------------------------------------------------------------------------以下是代码-------------------------------------------------------------------------------------

    #include <stdio.h>
    char a[10],b[10];
    int lena,lenb,nian1,y1,r1,nian2,y2,r2,ans,yue,ri,p;
    int ye[13]={0,31,28,31,30,31,30,31,31,30,31,30,31};
    int ru[13]={0,31,29,31,30,31,30,31,31,30,31,30,31};
    int main()
    {
    scanf("%s ",a);
    scanf("%s",b);
    nian1=(a[0]-'0')*1000+(a[1]-'0')*100+(a[2]-'0')*10+(a[3]-'0');
    y1=(a[4]-'0')*10+(a[5]-'0');
    r1=(a[6]-'0')*10+(a[7]-'0');
    nian2=(b[0]-'0')*1000+(b[1]-'0')*100+(b[2]-'0')*10+(b[3]-'0');
    y2=(b[4]-'0')*10+(b[5]-'0');
    r2=(b[6]-'0')*10+(b[7]-'0');
    for(int i=nian1;i<=nian2-1;i++)
    { p=i;
    if((i%4==0&&i%100!=0)||i%400==0)
    { yue=(p%10)*10+((p/10)%10);
    if(yue<=12&&yue>=1)
    { ri=((p/100)%10)*10+((p/1000)%10);
    if(ru[yue]>=ri)
    { ans++;
    }
    else continue;
    }
    else continue;
    }
    else
    { yue=(p%10)*10+((p/10)%10);
    if(yue<=12&&yue>=1)
    { ri=((p/100)%10)*10+((p/1000)%10);
    if(ye[yue]>=ri)
    { ans++;
    }
    else continue;
    }
    else continue;
    }
    }
    p=nian2;
    if((nian2%4==0&&nian2%100!=0)||nian2%400==0)
    { yue=(p%10)*10+((p/10)%10);
    if(yue<=12&&yue>=1)
    { ri=((p/100)%10)*10+((p/1000)%10);
    if(ru[yue]>=ri)
    { ans++;
    }
    }
    }
    else
    { yue=(p%10)*10+((p/10)%10);
    if(yue<=12&&yue>=1)
    { ri=((p/100)%10)*10+((p/1000)%10);
    if(ye[yue]>=ri)
    { ans++;
    }
    }
    }
    printf("%d ",ans);
    return 0;
    }

  • 相关阅读:
    最小生成树(Prim和Kruscal)
    SPFA(还是稍微写写吧,虽然没什么用)
    最短路径(随便写写)(Floyd,Bellman-Ford,Dijkstra)
    Just a Hook HDU
    数论逆元
    最长上升子序列(LIS)算法(附Codeforces Round #641 (Div. 2),B题题解)
    Educational Codeforces Round 86 (Rated for Div. 2)
    Codeforces Round #633 (Div. 2)
    Codeforces Round #631 (Div. 2)
    Mayor's posters(线段树离散化)
  • 原文地址:https://www.cnblogs.com/new-hand/p/6105730.html
Copyright © 2011-2022 走看看