Python--回文数
取得大于某个数的最小回文数字:
[coolcode lang="python"]
import sys
def palin(num):
num_int=int(num)
length=len(num)-1
if(num_int ==10**length-1):
num_int=10**length
num=str(num_int)
length=len(num)
max=0
for i in xrange(length):
max+=9*(10**i)
split_index=length/2
a=[]
for t in xrange(num_int,max+1):
t_str=str(t)
for i in xrange(split_index):
a.append(t_str[i]==t_str[length-i-1])
a=filter(None,a)
if(len(a)!=split_index):
a=[]
else:
return t
def main():
n = int(sys.stdin.readline())
a=[None]*n
for i in xrange(n):
num =sys.stdin.readline()
a[i]=num
for i in xrange(n):
para=a[i].replace('\n','')
p=palin_2(para)
print p
main()
[/coolcode]
这个方法的取值范围是int型