t1 = input() t2 = input() start = int(t1[:4]) end = int(t2[:4]) cnt = 0 for y inrange(start,end+1): y_str = f'{y:04d}' m = int(y_str[::-1][:2]) d = int(y_str[::-1][2:]) if judge(y,m,d): res = f'{y:04d}{m:02d}{d:02d}' if t1 <= res <= t2: cnt += 1
print(cnt)
暴力遍历:过不了全部样例
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
from datetime import datetime,timedelta
defcheck(a): return a == a[::-1]
t1 = datetime.strptime(input(),'%Y%m%d') t2 = datetime.strptime(input(),'%Y%m%d') current = t1 cnt = 0 while current <= t2: tmp = datetime.strftime(current,'%Y%m%d') if check(tmp): cnt += 1 current += timedelta(days=1)