题解 | #火车进站#

火车进站

http://www.nowcoder.com/practice/97ba57c35e9f4749826dc3befaeae109

 
def hcrz(wait, instack, out):
    if wait:
        hcrz(wait[1:], instack + [wait[0]], out)
    if instack:
        hcrz(wait, instack[:-1], out + [instack[-1]])
    if not wait and not instack:
        out_list.append(" ".join(map(str, out)))
data_list = []
 
for i in sys.stdin:
    data_list.append(i.strip())
new_list = []
for j in range(1,int(len(data_list)/2+1)):
    new_list.append(list(map(int,data_list[2*j-1].split(" "))))
for i in new_list:
    out_list = []
    hcrz(i,[],[])
    out_list.sort()
    for j in out_list:
        print(j)
全部评论

相关推荐

无情咸鱼王的秋招日记之薛定谔的Offer:好拒信,偷了,希望有机会用到
点赞 评论 收藏
分享
10-10 17:54
点赞 评论 收藏
分享
评论
点赞
1
分享
牛客网
牛客企业服务