题解 | #MP3光标位置#

MP3光标位置

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

# 每屏显示4首歌,光标初始位置为第1首歌

N=int(input())  # 歌曲数量
order=input()   # 命令 U 往上/D 往下
n=4             # 每屏显示歌曲数量
cursor=1        # 光标初始位置为第1首歌

if N<=4:
    present_list=[i for i in range(1,N+1)]
    for i in order:
        if i=='U':
            if cursor==1:
                cursor = N
            else:
                cursor -= 1
        elif i=='D':
            if cursor==N:
                cursor = 1
            else:
                cursor += 1

else:
    present_list=list(range(1,n+1))
    for i in order:
        if i=='U':
            if cursor==1:
                cursor = N
            else:
                cursor -= 1
        elif i=='D':
            if cursor==N:
                cursor = 1
            else:
                cursor += 1

        if cursor==N:
            present_list=list(range(N+1-n,N+1))
        elif cursor==1:
            present_list=list(range(1,n+1))
        elif min(present_list)<=cursor<=max(present_list):
            present_list=present_list
        elif cursor<min(present_list):
            present_list=list(map(lambda i:i-1,present_list)) 
            # present_list 每个值减1
        elif cursor>max(present_list):
            present_list=list(map(lambda i:i+1,present_list))
            # present_list 每个值加1

for i in present_list:
    print(i,end=' ')
print()   
print(cursor)

全部评论

相关推荐

06-23 11:28
门头沟学院 Java
牛客91966197...:也有可能是点拒绝的时候自动弹的话术
点赞 评论 收藏
分享
05-26 10:24
门头沟学院 Java
qq乃乃好喝到咩噗茶:其实是对的,线上面试容易被人当野怪刷了
找工作时遇到的神仙HR
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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