洛谷 P2010 回文日期
来源:互联网 发布:一洋淘宝工具箱 编辑:程序博客网 时间:2024/06/05 05:12
1.从起始日期到终止日期枚举2.由于只有8位,可以用长整型3.回文判断: 每一次转化成字符串s 或者 直接利用div,mod计算首尾位判断4.考虑day的情况 28的时候如果是闰年且是二月就 year+0,month+1,day=0 29的时候如果是平年且是二月就 year+0,month+1,day=0 30的时候如果是month in [4,6,9,11] 就 year+0,month+1,day=0 31的时候 day in [28,29,30] 没有清零 所以 month in [1,3,5,7,8,10,12] 这时候month有两种情况: 1.month=12 :year+1,month=1,day=0 2.month<>12: year+0,month+1,day=0 5.day+1 6.把year,month,day转化成八位数; 更新first。
var ans,first,last,year,month,day,i:longint; s:string; flag:boolean;begin assign(input,'date.in'); reset(input); assign(output,'date.out');rewrite(output); readln(first); readln(last); ans:=0; while first<=last do begin str(first,s); if (s[1]=s[8]) and (s[2]=s[7]) and (S[3]=s[6]) and (s[4]=s[5]) then flag:=true else flag:=false; if flag then inc(ans); year:=first div 10000; month:=first mod 10000 div 100; day:=first mod 100; case day of 28:if (year mod 4<>0) and (month=2) then begin month:=month+1; day:=0; end; 29:begin if (((year mod 4=0) and (year mod 100<>0)) or (year mod 400=0)) and (month=2) then begin month:=month+1; day:=0; end; end; 30:if (month=4) or (month=6) or (month=9) or (month=11) then begin month:=month+1; day:=0; end; 31:if month=12 then begin year:=year+1; month:=1; day:=0; end else begin month:=month+1; day:=0; end; end; day:=day+1; first:=year*10000+month*100+day; end; writeln(ans); close(input); close(output);end.
2 0
- 洛谷 P2010 回文日期
- 洛谷 P2010 回文日期
- 洛谷 P2010 回文日期
- 洛谷 P2010回文日期
- Vijos P2010 回文日期【回文+日期计算】
- 回文日期
- 【NOIP2016】回文日期
- [NOIP2016普及] 回文日期
- 回文日期(date)
- 回文日期(NOIP2016)
- 100年的回文日期
- NOIP2016普及组-回文日期
- NOIP2016 第二题 回文日期
- NOIP2016 第二题 回文日期
- NOIP2016普及组第二题——回文日期
- NOIP2016普及组第二题——回文日期
- 【NOIP2016普及组】复赛——回文日期
- 【noip题目代码】回文日期;vetor,模拟,iterator
- IDEA 出现 Unsupported major.minor version 52.0
- 【C语言】 约瑟夫环问题
- 安卓开发中常见的RGB颜色表
- 填报表下拉数据集使用需知
- 测距和避障传感器——雷达
- 洛谷 P2010 回文日期
- Sass关于颜色函数的乐趣
- 编译引用第三方jar包的类
- Delphi 中生成指定范围不重复的随机数
- redis-trib创建redis集群错误
- jQuery源码阅读心得(一) 自调用匿名函数
- maven1—maven介绍及环境搭建
- 第7篇白板之图片旋转标记做成箭头(三)及quadraticCurveTo
- python实时处理log文件脚本