1 条题解

  • 0
    @ 2023-3-3 15:42:24
    /*
    P2010 [NOIP2016 普及组] 回文日期
    方法1:        直接判断每个日期 
    函数判断是否回文日期  
            hw(int t)         
    month[13]={0,31,28,31,30,.....}
    枚举范围内的所有时间:t
            判断t  
            for(t:date1-date2) 20110199
    for(i:year1-year2)
            for(j:1-12)
                    if(leap(i)) month[2]=29
                            else  month[2]=29
                     for(k:1-month[i]) //闰年 
                             t=i*10000+j*100+k;
                                     if(date1<=t<=date2)
                                             ans++;
                     
    方法2:        直接判断每个日期  一层循环
    函数判断是否回文日期  
            hw(int t)         
            legal(int t) 
                    提取月份 mon(1-12)  
                            几号day:得和 月份 年份结合判断         
            for(t:date1-date2)
    
            
    方法三:枚举回文日期
            一共366个回文日期,构造出所有回文日期 t,判断是否在(date1,date2)范围内 
            hw(int n)输出反向的n 
            t:构造出回文日期 
            for(i:1-12)月 
                    for(j:month[i])
                             year=day%10\*1000+day/10\*100+month%10\*10+ month/10
                             t= year*10000+i*100+j 
                                     if(date1<=t<=date2)
                                             ans++;         
    
    */
    // 回文日期
    #include<iostream> 
    using namespace std;
    int i,j,n,m,a,b,c,sum,ans;
    int s[13]={0,31,29,31,30,31,30,31,31,30,31,30,31};
    int main()
    {
        cin>>n>>m;
        for (i=1;i<=12;i++)//枚举月和日 
            for (j=1;j<=s[i];j++)
            {
                c=(j%10)*1000+(j/10)*100+(i%10)*10+(i/10);//算出前四位。
                sum=c*10000+i*100+j;//算出整个日期 
                if (sum<n||sum>m) continue;
                ans++;//统计 
            }
        cout<<ans<<endl;
        return 0;
    }
    
    • 1

    信息

    ID
    739
    时间
    1000ms
    内存
    256MiB
    难度
    10
    标签
    递交数
    2
    已通过
    1
    上传者