对了一半,剩下一半超时 了,求救
查看原帖
对了一半,剩下一半超时 了,求救
611860
hwqdsg楼主2024/4/9 14:40
import math
import statistics
import sys
import copy
sys.setrecursionlimit(int(1e8))

months = [0,31,28,31,30,31,30,31,31,30,31,30,31]

def check(date):
    year = int(date/10000)
    month = int(date/100)%100
    day = date%100
    if day==0 or month<=0 or month>12:
        return 0
    if month!=2 and day > months[month]:
        return 0
    if month==2:
        if (year%4==0 and year%100!=0) or year %400==0:
            if day > 29:
                return 0
        else:
            if day>28:
                return 0
    return 1
def check_huiwen(s):
    s = str(s)
    x = s
    s = list(s)
    s.reverse()
    s = ''.join(s)
    if x==s:
        return 1
    return 0

def check_abab(s):
    s = str(s)
    if check_huiwen(s):
        if s[0]!=s[2] or s[1]!=s[3] or s[0]==s[1]:
            return 0
        return 1


date = int(input())

flag = 0

while 1:
    date += 1
    if check(date):
        if check_huiwen(date) and flag==0:
            print(date)
            flag = 1
        if check_abab(date):
            print(date)
            break

2024/4/9 14:40
加载中...