Loading

蓝桥杯 回文日期

在这里插入图片描述
模拟

n = int(input())

def check(x):
  m = int(x[:2])
  d = int(x[2:4])
  x = int(x)
  if 1<=m<=12:
    if m == 2:
      if (x%4==0 and x%100!=0) or x%400==0:
        if d<=29:
          return True
        else:
          return False
      else: 
        if d<=28:
          return True
        else:
          return False
    if m in [1,3,5,7,8,10,12]:
      if d<=31:
        return True
      else:
        return False
    else:
      if d<=30:
        return True
      return False
  return False
arr1 = []
arr2 = []
for i in range(1000, 9999):
  x1 = str(i)[::-1]
  x2 = (str(i)[:2]+str(i)[:2])[::-1]
  if check(x1) and int(x1[::-1]+x1)>n:
    arr1.append(int(x1[::-1]+x1))
  if check(x2) and int(x2[::-1]+x2)>n:
    arr2.append(int(x2[::-1]+x2))

print(arr1[0])
print(arr2[0])
posted @ 2021-04-13 09:06  XiaoJ_c  阅读(77)  评论(0)    收藏  举报