题解 | #MP3光标位置#

MP3光标位置

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

自己写的辣鸡代码记录一下
song_list = list(range(1,int(input())+1))
order = input()
cur = [1,[1,2,3,4]]
def go(order):
    global song_list
    if len(song_list)<=4:
        if order == 'U':
            cur[0] = song_list[song_list.index(cur[0])-1]
        else:
            if cur[0] == len(song_list):
                cur[0] = 1
            else:
                cur[0] = song_list[song_list.index(cur[0])+1]
        cur[1] = song_list
    else:
        if order == 'U':
            if cur[0] == 1:
                cur[1] = song_list[-4:]
                cur[0] = song_list[-1]
            elif cur[1].index(cur[0])>0:
                cur[0] = song_list[song_list.index(cur[0])-1]
            elif cur[1].index(cur[0])==0:
                cur[0] = song_list[song_list.index(cur[0])-1]
                cur[1] = [i-1 for i in cur[1]]
        elif order == 'D':
            if cur[0] == song_list[-1]:
                cur[1] = song_list[:4]
                cur[0] = song_list[0]
            elif cur[1].index(cur[0])<3:
                cur[0] = song_list[song_list.index(cur[0])+1]
            elif cur[1].index(cur[0])==3:
                cur[0] = song_list[song_list.index(cur[0])+1]
                cur[1] = [i+1 for i in cur[1]]
                
for i in order:
    go(i)
print(*cur[1])
print(cur[0])


全部评论

相关推荐

微风不断:兄弟,你把四旋翼都做出来了那个挺难的吧
点赞 评论 收藏
分享
评论
点赞
收藏
分享
牛客网
牛客企业服务