拼多多2019.09.01秋招笔试 算法工程师

image.png

image.png

image.png
/*
小编是一名python开发工程师,这里有我自己整理了一套最新的python系统学习教程,包括从基础的python脚本到web开发、爬虫、数据分析、数据可视化、机器学习等。想要这些资料的可以关注小编。且我这有个学习Python基地,里面有很多学习资料,感兴趣的+Q群:895817687
*/
def pdd_1():
# 根据取模运算,将奇数和偶数分开,分别排序,之后拼接输出
# nums, N = input().split(';')
aa = '555503,772867,756893,339138,399447,40662,859037,628085,855723,974471,599631,636153,581541,174761,948135,411485,554033,858627,402833,546467,574367,360461,566480,755523,222921,164287,420256,40043,977167,543295,944841,917125,331763,188173,353275,175757,950417,284578,617621,546561,913416,258741,260569,630583,252845;10'
nums, N = aa.split(';')
nums = map(int, nums.split(','))
N = int(N)
nums_0, nums_1 = [], []
for i in nums:
if i % 2 == 0:
nums_0.append(i)
nums_0.sort(reverse=True)
else:
nums_1.append(i)
nums_1.sort(reverse=True)
nums = nums_0 + nums_1
for i in range(N - 1):
print(nums[i], end=',')
print(nums[N], end='')
def pdd_2():
# DFS 求解,着重找到递归结束的条件
# DFS 注意顺序,以满足输出的字典序要求,避免二次排序
def check(nums0, new_0, nums1, new_res):
if not nums0:
if len(new_0) == len(nums1):
for i in range(len(new_0)):
if new_0[i] != nums1[i]:
return
res.append(new_res)
return
num = nums0[0]
nums0 = nums0[1:]
check(nums0, new_0, nums1, new_res + ['d'])
check(nums0, [num] + new_0, nums1, new_res + ['l'])
check(nums0, new_0 + [num], nums1, new_res + ['r'])
# N = int(input())
N = 1
for i in range(N):
# nums_0 = list(map(int, input().split()))
# nums_1 = list(map(int, input().split()))
nums_0 = [1, 2, 3]
nums_1 = [3]
print('{')
if set(nums_0) > set(nums_1):
res = []
check(nums_0, [], nums_1, [])
for j in res:
print(' '.join(j))
print('} ')
网友评论