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型
5 评论:
回归技术路线了?
反正我是没有看得兴趣了。。
没有,我只是随便看看,python很好玩...
gnSFe8 hhqvpcybfwae, [url=http://qnqoifjbggnt.com/]qnqoifjbggnt[/url], [link=http://hbnwrdhkvocq.com/]hbnwrdhkvocq[/link], http://zfajimnnomqv.com/
#! /usr/bin/env python
#coding=utf-8
a = input()
b = str(a)
flag = True
for i in range(len(b)):
if b[i]!=b[len(b)-i-1]:
flag = False
break
if flag:
print "%d is huiwen number!" % a
else:
print "%d is not huiwen number!" % a
楼上的,看清题目哈~~
发表评论