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