题解 | #MP3光标位置#

MP3光标位置

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

指令只有两种,在两种指令下,根据光标的位置做进一步的判断就好

不管是那种指令,光标只有两种位置需要对显示列表进行调整,

在up的指令下,光标在第一首歌和列表的第一首歌时,需要对列表进行调整,其他情况下只需要修改index即可

down指令亦然

n = int(input())
comm = input()

mu_list = [i for i in range(n+1)]
start = 1
end = 4 if n >=4 else n
index = 1
for co in comm:
    if co == 'U':  
        if index == 1: 
            start = n - 3 if n-3 > 0 else 1 
            end = n
            index = n
        elif index == start:
            start -= 1
            end -= 1
            index -= 1
        else:
            index -=1
    if co == 'D':
        if index == n:
            start = 1
            end = 4 if n >= 4 else n
            index = 1
        elif index == end:
            start += 1
            end += 1
            index += 1
        else:
            index +=1
print(' '.join(str(i) for i in range(start,end+1)))
print(index)

全部评论

相关推荐

酷酷的喜马拉雅山:感觉这比一直在初筛不动的好多了
点赞 评论 收藏
分享
Aurora23:属于挂一半,暂时进池子了,隔一段时间没有其他组捞的话就彻底结束了
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务