4个数字凑最大时间
来源:互联网 发布:伤感的网络歌曲 编辑:程序博客网 时间:2024/06/05 04:25
Give four digits, find the maximum valid time that can be displayed on a digital clock(in 24 hours format) using those digits. For example, given digits 1, 8, 3, 2, the maximum valid time is "23:18".
<pre name="code" class="python">import functoolstest_arr = [ [1, 8, 3, 2], [2, 4, 0, 0], [3, 0, 7, 0], [9, 1, 9, 7], [2, 6, 0, 6]]def findAllRange(arr, pool, length): if length >= 4:
<span style="font-family: Arial, Helvetica, sans-serif;"><span style="white-space:pre"></span>pool.append(arr[:])</span>
<span style="font-family: Arial, Helvetica, sans-serif;"><span style="white-space:pre"></span>return</span>
<span style="font-family: Arial, Helvetica, sans-serif;"><span style="white-space:pre"></span>for i in range(0, length + 1):</span>
<span style="font-family: Arial, Helvetica, sans-serif;"><span style="white-space:pre"></span>arr[i], arr[length] = arr[length], arr[i]</span>
findAllRange(arr, pool, length + 1) arr[length], arr[i] = arr[i], arr[length]
def isTime(pool): res = [] for i in pool: if not (((i[0] * 10 + i[1]) > 23) or ((i[2] * 10 + i[3]) > 59)): res.append(i) return resdef comp(a, b): for i in range(0, 4): if a[i] < b[i]: return 1 elif a[i] == b[i]: continue else: return -1 return 0def solution(A, B, C, D): arr = [A, B, C, D] pool = [] findAllRange(arr, pool, 0) pool = sorted(pool, key = functools.cmp_to_key(comp)) pool = isTime(pool) if len(pool) <= 0: return 'NOT POSSIBLE' else: return '%d%d:%d%d' % (pool[0][0], pool[0][1], pool[0][2], pool[0][3])if __name__ == '__main__': for i in test_arr: print(solution(i[0], i[1], i[2], i[3]))
0 0
- 4个数字凑最大时间
- 从1亿个数字中取出最大的100个数字- 位图排序(空间换时间)
- 使用if--else 在4个数字中找到最大数字
- 11个中最大的10个数字
- 求任意10个数字中最大的一个数字
- uva10905连接n个数字,使得连成的数字最大
- 有 n 个无序整数( n>10000), 则找出其中最大的 M 个数字( 5<M<10), 所需要的最小时间复杂度为:
- 100亿个数字中找出最大的10个
- 删除K个数字,使剩下的数字串最大
- 十亿数据中求最大一百个数字
- 用arg_list查找n个数字中的最大者
- 删除K个数字,使剩下的数字串最大
- 输入5个数字,输出最大的数
- 100亿数据找出最大的1000个数字
- 数字组合问题(N个正整数连接起来最大)
- 从键盘接受一个数字,打印该数字表示的时间,最大单位到天
- 找出n个数字的中位数至少需要的时间
- 课后练习,输入3个数字,选择输出最大的一个数字
- ASP.NET缓存之数据库缓存依赖(二)
- spring bean的生命周期
- Non-Programmer'sTutorial for Python 3/File IO
- Python File I/O
- 洛谷 P1462 通往奥格瑞玛的道路
- 4个数字凑最大时间
- 第五章 5.5 跳转语句
- 机房收费系统—登录
- android View Animation之Tween animation
- 【JZ雅礼联考】斐波那契 题解
- 引入思考的电影电视动漫
- 机房收费系统--上下机
- iOS控制反转(IoC)与依赖注入(DI)的实现
- 【MyBatis】MyBatis分页插件PageHelper的使用