zoukankan      html  css  js  c++  java
  • P2010回文日期

    这道题是2016年普及组的题,难度等级为普及—。

    这道题仍然是个模拟题。有两种策略:1.枚举回文,看日期是否存在2.枚举日期,看是否是回文。显然,前者要快很多,并且准确。本蒟蒻第一次便使用了后者,bug频出,看了题解后想到了前者。并且在取位与字符串处理上出了问题qaq。最后被卡了几个数据点......

    1.字符串中转int:-48即可。
    2.调bug的时候可以规范输出来查错误。
    3.模拟题一定要思考好for谁快。
    4.模拟题思路一定要清晰,别先动键盘,先动笔,确定好有把握的策略。

    伪代码:
    string str1,str2;
    int year1,year2;
    int month1,month2;
    int day1,day2;
    int ans=0;
    int day[12]={31,28,31,30,31,30,31,31,30,31,30,31};
    int rday[12]={31,29,31,30,31,30,31,31,30,31,30,31};
    bool judge_r(int x){
    if(x%4000||(x%40&&x%10!=0)){
    return true;
    }
    else return false;
    }
    int main(){
    cin>>str1;
    cin>>str2;
    year1=(str1[0]-48)1000+(str1[1]-48)100+(str1[2]-48)10+(str1[3]-48);
    year2=(str2[0]-48)
    1000+(str2[1]-48)100+(str2[2]-48)10+(str2[3]-48);
    month1=(str1[4]-48)10+(str1[5]-48);
    month2=(str2[4]-48)
    10+(str2[5]-48);
    day1=(str1[6]-48)10+(str1[7]-48);
    day2=(str2[6]-48)
    10+(str2[7]-48);
    /cout<<year1<<month1<<day1<<endl;
    cout<<year2<<month2<<day2<<endl;
    /
    for(int i=year1;i<=year2;i++){
    int month=(i%10)10+(i%100)/10; //回文
    int date=i/1000+((i%1000)/100)
    10;
    // cout<<month<<" "<<date<<endl;
    if(judge_r){//闰年不存在
    if(month>12) continue;
    if(date>rday[month]) continue;
    }
    else{//普通年不存在
    if(month>12) continue;
    if(date>day[month]) continue;
    }
    if(iyear1){//必须大于左端点
    if(month<month1){
    continue;
    }
    else{
    if(month
    month1&&date<day1){
    continue;
    }
    }
    }
    if(iyear2){//必须小于右端点
    if(month>month2){
    continue;
    }
    else{
    if(month
    month2&&date>day2){
    continue;
    }
    }
    }
    ans++;
    }
    cout<<ans;
    return 0;
    }

    待到oi十一月,我花开后百花杀。
  • 相关阅读:
    怎么用javascript进行拖拽[zt]
    FireFox不支持disableoutputescaping(zt)
    xslt中的Javascript取得xml中的参数
    因为查询无法同时更新聚集键和 text、ntext 或 image 列
    FireFox下操作IFrame
    xslt中formatnumber()
    linuxgrepregular expression(regex)
    pl/sqlescape& quotation
    linuxsed command
    linuxfind command(transferred)
  • 原文地址:https://www.cnblogs.com/china-mjr/p/11197453.html
Copyright © 2011-2022 走看看