|
发表于 2019-12-5 15:09:30
|
显示全部楼层
原文看起来好长,发个短的- #每日一题文档,旨在练习Pyhon熟练度和提高算法
- def fun284(list_Num = [1,2,3],n = 10):
- #n不能小于数组中元素位数最长的值
- def buquan(num,len_num = n):
- #将所有整数通过末尾加 原来末尾的最后一位 转换为长度相同的整数
- while num <10**n-1:
- num = num * 10 +num%10
- return num
- s = ''
- list_Num.sort(key = buquan ,reverse = True)#将数字变为字符串降序
- for i in list_Num:
- s += str(i)
- return int(s)
-
- print('输入为:[1,20,23,4,8]\t输出最大整数为:%d' %(fun284(list_Num = [1,20,23,4,8])) )
- print('输入为:[4,6,65]\t输出最大整数为:%d' %(fun284(list_Num = [4,6,65])) )
- print('输入为:[262,242,29,282,2822]\t输出最大整数为:%d' %(fun284(list_Num = [262,242,29,282,2822])) )
- print('输入为:[650, 580, 66, 9, 661, 59]\t输出最大整数为:%d'%(fun284(list_Num = [650, 580, 66, 9, 661, 59])) )
- print('输入为:[2,221]\t输出最大整数为:%d' %(fun284(list_Num = [2,221])) )
- print('输入为:[4,6,67]\t输出最大整数为:%d' %(fun284(list_Num = [4,6,67])) )
- >>>
- ==================== RESTART: C:\Users\13555\Desktop\1.py ====================
- 输入为:[1,20,23,4,8] 输出最大整数为:8423201
- 输入为:[4,6,65] 输出最大整数为:6654
- 输入为:[262,242,29,282,2822] 输出最大整数为:292822822262242
- 输入为:[650, 580, 66, 9, 661, 59] 输出最大整数为:66661650595809
- 输入为:[2,221] 输出最大整数为:2221
- 输入为:[4,6,67] 输出最大整数为:6764
- >>>
复制代码 |
|