题解 | #MP3光标位置# 少于四首歌的情况好容易漏啊
MP3光标位置
https://www.nowcoder.com/practice/eaf5b886bd6645dd9cfb5406f3753e15
n = int(input()) order = list(input()) #分成两部分 #计算当前歌曲 这个相当于一个取余循环 记录总的操作数取余就行了 #计算当前光标是在第几行[1,2,3,4] #初始是1 D [1,2,3]->[2,3,4] 4位置翻页不翻页根据当前歌曲num == n讨论一下 num_p = 0 # index 0 1 2 3 4 ... n-1 -1=> n-1 # value 1 2 3 4 5 ... n # num = (num_p+n) % n + 1 local_p = 1 #1 2 3 4 for od in order: if od == 'D': num = (num_p+n) % n + 1 num_p += 1 if local_p in [1, 2, 3]: local_p = local_p+1 elif local_p == 4: # 到底翻页 local_p = 1 if num == n else 4 else: num = (num_p+n) % n + 1 num_p -= 1 if local_p in [2, 3, 4]: local_p = local_p-1 elif local_p == 1: # 到顶翻页 local_p = 4 if num == 1 else 1 num = (num_p+n) % n + 1 left = local_p - 1 right = 4 - local_p list_out = [i for i in range(num-left, num+right+1)] if n>=4 else [i+1 for i in range(n)] print(" ".join([str(i) for i in list_out])) print(num)