蓝桥杯入门练习 特殊回文数

仅供参考:

import itertools
n=int(input())
j = [i for i in range(0,10)]
iter = itertools.product(j,repeat=2)
if n<=45:
    for i in iter:
        for p in range(0,10):
            if (i[0]+ i[1])*2 + p == n :
                t = str(i[0])+str(i[1])
                t_=str(i[1])+str(i[0])
                if i[0] != 0:   
                    print(int(t+str(p)+t_))
            elif (i[0]+ i[1])*2 + p >n:
                break
if n%2==0:
    iter=itertools.product(j,repeat=3)
    for i in iter:
        if (i[0]+i[1]+i[2])*2 ==n:
            t = str(i[0])+str(i[1])+str(i[2])
            t_ = t[::-1]
            if i[0] != 0:
                print(int(t+t_))

你可能感兴趣的:(经验分享)