小于n的最大数字
Posted lyz_fish
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了小于n的最大数字相关的知识,希望对你有一定的参考价值。
# encoding: utf-8
# a = input("please input a number:")
# print("hello world")
def find_max(n,A:list):
every_bit,answer = list(),list()
counter,tem_out_n = 1,n
while tem_out_n != 0:
tem_last = tem_out_n%10
tem_out_n //= 10
every_bit.append(tem_last)
counter += 1
# every_bit
print('counter\\t',counter)
print(every_bit)
for index,n_bit in enumerate(reversed(every_bit)):
temp_bit = A[0]
# answer.append(temp_bit)
for a_id,a in enumerate(A):
if a> temp_bit and a==n_bit and a_id != 0:
temp_bit = a
# answer.pop()
# answer.append(temp_bit)
if a> temp_bit and a<n_bit and a_id != 0:
answer.append(a)
for _ in range(counter-index-1):
answer.append(max(A))
return answer
answer.append(temp_bit)
return answer
if __name__ == '__main__':
print(find_max(23121,[2,4,9]))
以上是关于小于n的最大数字的主要内容,如果未能解决你的问题,请参考以下文章