题解 | #MP3光标位置#
MP3光标位置
https://www.nowcoder.com/practice/eaf5b886bd6645dd9cfb5406f3753e15
n = int(input()) s = input() # UUUU song = [] for i in range(1,n+1): song.append(i) f = 1 # f表示当前页第一首歌的位置。代表翻页。 p = 1 # 光标位置 光标初始的位置为第1首歌(p = [1,2,3,4]) if n <= 4: # 歌曲总数<=4的时候,不需要翻页,只是挪动光标位置。 for i in s: if i == 'U': if p == 1: p = n else: p = p-1 elif i == 'D': if p == n: p = 1 else: p = p+1 else:#n>4 for i in s: if i == 'U': if f == 1 and p == 1: f = n-3 p = 4 elif p == 1: f = f-1 else: p = p-1 elif i == 'D': if f == n-3 and p == 4: f = 1 p = 1 elif p == 4: f = f+1 else: p = p+1 #print(f,p) print(*song[f-1:f-1+4]) # f表示当前页第一首歌的位置,初始值是1,所以歌曲列表是song[f-1,f-1+4] print(f-1+p) # f-1+p,表示的是当前选中的歌曲