赞
踩
一、撸代码
若一个数(首位不为0)从左到右读与从右到左读都是一样,这个数就叫做回文数,例如12521就是一个回文数。 给定一个正整数,把它的每一个位上的数字倒过来排列组成一个新数,然后与原数相加,如果是回文数则停止,如果不是,则重复这个操作,直到和为回文数为止。给定的数本身不为回文数。 例如:87则有: STEP1: 87+78=165 STEP2: 165+561=726 STEP3: 726+627=1353 STEP4: 1353+3531=4884 现在给你一个正整数M(12 <= M <= 100),输出最少经过几步可以得到回文数。如果在8步以内(含8步)不可能得到回文数,则输出0。 例如:M=87,则输出4.
代码:没啥可说的比较简单
- def check(num):
- str_num = str(num)
- return str_num == str_num[::-1]
-
- def turn(nums):
- str_nums = str(nums)
- return int(str_nums[::-1])
-
- def functions(nums):
- found = False
- count = 0
- while not found and count <= 8:
- count += 1
- tmp = (nums + turn(nums))
- print(tmp)
- if check(tmp):
- found = True
- else:
- nums = tmp
- if count <= 8:
- return count
- else:
- return 0
-
- nums = 87
- print(functions(nums))

二、提问环节
重点阐述一下以往的项目,担任什么角色,遇到什么困难,模型怎么改进的,为什么这么改进,等。。。
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。