蓝桥杯python组——日期问题 import sys x , y , z = map ( int , input (). split ( '/' )) ans = [] mon = [ 0 , 31 , 28 , 31 , 30 , 31 , 30 , 31 , 31 , 30 , 31 , 30 , 31 ] def run ( x ): #判断闰年 if x % 4 == 0 and x % 100 != 0 or
蓝桥杯python组——日期问题
x,y,z=map(int,input().split('/'))
ans=[]
mon=[0,31,28,31,30,31,30,31,31,30,31,30,31]
def run(x):#判断闰年
if x%4==0 and x%100!=0 or x%400==0:
return True
return False
def check(x,y,z):
if x<60:
xx=2000+x
else:
xx=1900+x
if run(xx):
mon[2]+=1
if z<=mon[y]:
ans.append((xx,y,z))
mon[2]-=1
else:
if z<=mon[y]:
ans.append((xx,y,z))
#nyr
if 0<y<=12 and 0<z<=31:
check(x,y,z)
#yrn
if 0<x<=12 and 0<y<=31:
check(z,x,y)
#ryn
if 0<y<=12 and 0<x<=31:
check(z,y,x)
ans.sort()#年份排序
ans=list(dict.fromkeys(ans))
#去重的作用,因为字典的键是不能重复的
for x in ans:#输出加上0
print("{:04}-{:02}-{:02}".format(x[0],x[1],x[2]))
谢谢大家的支持,您的一键三连是 罡罡同学前进的最大动力!