小米麪試題目: 一副從1到n的牌,每次從牌堆頂取一張放桌子上,再取一張放牌堆底,直到手中沒牌,最後桌子上的牌是從1到n有序,設計程序,輸入n,輸出牌堆的順序數組

題目:一副從1到n的牌,每次從牌堆頂取一張放桌子上,再取一張放牌堆底,直到手中沒牌,最後桌子上的牌是從1到n有序,設計程序,輸入n,輸出牌堆的順序數組

之前這道題很火,所以我也試着寫了答案,今天才發出來。結果百度了一個題目的名字,還發現了Java版本的,我在寫之前沒有看任何人的東西,騙人是小狗。

經本人測試,算法處理木有問題。


from utils.result_process import success, aborted
import re
import copy


async def ls(app, request):

    test_list = [1,2,3,4,5,6]
    test_list_other = copy.deepcopy(test_list)
    n = 5
    # test_list = [x for x in list(range(n))]
    print('--------==========')
    print(test_list)
    other_List = []

    sign = True
    for i in range(len(test_list)+20):
        if test_list:
            if sign == False:
                test_list.append(test_list[0])
                test_list.remove(test_list[0])
                print('----=')
                print(test_list)
                sign = True
            elif sign == True:
                other_List.append(test_list[0])
                test_list.remove(test_list[0])
                print('-----')
                print(test_list)
                sign = False

    print('-=-=-=-=-=-=-=-=-=-=-=-=-')
    print(test_list)
    print(other_List)

    res_dict = {}
    res_list = []
    print('-=-=-=-test_list_other=-=-=-=-')
    print(test_list_other)
    for key, val in enumerate(test_list_other):
        for keyl, item in enumerate(other_List):
            if keyl == key:
                res_dict[item] = val

    print(res_dict)

    for i in range(len(test_list_other)):
        res_list.append(res_dict[i+1])
    print(res_list)
    return success()

def data_judge(data):
    if data % 2 == 0:
        return 'oushu'
    elif data % 2 == 1:
        return 'jishu'

Java版本在這裏

https://blog.csdn.net/weixin_42038771/article/details/81879300

 

 

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章