回文日期 python

 

改动于这篇文章(18条消息) python回文日期蓝桥杯解题思路_一台电脑走天下的博客-CSDN博客_回文日期python

他只能90分,因为每天每天的判断,会很慢。其实一年只需要判断一次就好。

#回文日期
import datetime
import calendar
# calendar.monthrange(2013,12)#返回指定 年份 的指定 月份 的第一天是星期几和这个月的天数。
N=input()
year,mm,day=eval(N[:4]),N[4:6],N[6:] #年月日

huiwen=[] #保存第一种回文日期类型
AB=[]  #保存ABABBABA型回文日期
k = 0
while len(huiwen)*len(AB)==0:
    if k==0:#判断本年的
        years = str(year)[4::-1]
        if int(years[0:2])<=12 and int(years[0:2])>=int(mm):#月份判断,是否满足mm到12月
            if int(years[0:2])>int(mm) or (int(years[0:2])==int(mm) and int(years[2:4])>int(day)):#判断日期是否在当前日期之后
                if int(years[2:4])<=calendar.monthrange(int(year),int(years[0:2]))[1]:#回文判断                                               
                    huiwen.append(str(year)+str(years))
                if str(years)[0] ==  str(years)[2] and str(years)[1] ==  str(years)[3]:
                    AB.append(str(year)+str(years))
        k = k+1
        continue
    #判断以后年的
    year += 1
    years = str(year)[4::-1]
    if int(years[0:2])<=12 and int(years[0:2])>0:
        if int(years[2:4])<=calendar.monthrange(int(year),int(years[0:2]))[1]:                                               
            huiwen.append(str(year)+str(years))
        if str(years)[0] ==  str(years)[2] and str(years)[1] ==  str(years)[3]:
            AB.append(str(year)+str(years))
print(huiwen[0])
print(AB[0]) 

  • 3
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值