题解 | #MP3光标位置#

MP3光标位置

http://www.nowcoder.com/practice/eaf5b886bd6645dd9cfb5406f3753e15

def myfunc(num,disp_l,disp_n,orde):
    if disp_l == [1,2,3,4] and disp_n == 1 and orde == 'U':
        disp_l = [ i for i in range(num-3,num+1) ]
        disp_n = num
    elif disp_l == [i for i in range(num-3,num+1)] and disp_n == num and orde == 'D':
        disp_l = [1,2,3,4]
        disp_n = 1
    elif disp_n == disp_l[0] and orde == 'U':
        disp_l = [ i - 1 for i in disp_l ]
        disp_n -= 1
    elif disp_n == disp_l[-1] and orde == 'D':
        disp_l = [ i + 1 for i in disp_l ]
        disp_n += 1
    elif orde == 'U':
        disp_n -= 1
    else:
        disp_n += 1
    return([disp_l,disp_n])

while True:
    try:
        number = int(input())
        orders = input()
        steps = 0
        for i in orders:
            if i == 'U':
                steps += 1
            else:
                steps -= 1
        if 0 < number <= 4:
            display_list = [ i for i in range(1,number + 1)]
            print(*display_list)
            if steps % number == 0:
                display_number = 1
            else:
                display_number = 1 + steps % number
            print(display_number)
        elif number > 4:
            display_list = [1,2,3,4]
            display_number = 1
            for order in orders:
                results = myfunc(number,display_list,display_number,order)
                display_list,display_number = results[0],results[1]
            print(*display_list)
            print(display_number)
    except:
        break
全部评论

相关推荐

OffersGettttt:为啥现在看到大多数公司都有提前实习的要求
点赞 评论 收藏
分享
jack_miller:我给我们导员说我不在这里转正,可能没三方签了。导员说没事学校催的时候帮我想办法应付一下
点赞 评论 收藏
分享
点赞 收藏 评论
分享
牛客网
牛客企业服务