题解 | #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)

全部评论

相关推荐

07-03 16:02
门头沟学院 Java
点赞 评论 收藏
分享
点赞 评论 收藏
分享
小浪_Coding:找硬件测试,也可兼顾软测欧, 简历还可以的 ,注意排版,项目写的有条理一点, 然后个人技能多加点, 润色好简历之后就开始沟通海投了,深圳,东莞这边做硬件相关的公司还不少, 医疗类,仪器类的都可以尝试
点赞 评论 收藏
分享
练习生懒羊羊:开飞机把这个公司创飞吧
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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