题解 | #MP3光标位置#冷静下来读题吧
MP3光标位置
https://www.nowcoder.com/practice/eaf5b886bd6645dd9cfb5406f3753e15
n = int(input()) order = input() lst = [] for i in range(1,n+1): lst.append(i) i = 0 position = 0 for k in order: if k == 'U': if i == 0: i = n-1 position = min(3,n-1) else: i -= 1 if position > 0: position -= 1 else: if i == n-1: i = 0 position = 0 else: i += 1 if position < 3: position += 1 tmp = [lst[i]] def tmp_add(count,position): if position - count < 0 and position + count >min(3,n-1): return if position-count > -1: tmp.insert(0,lst[(i-count+n)%n]) if position+count < 4: tmp.append(lst[(i+count+n)%n]) tmp_add(count+1,position) tmp_add(1,position) for j in tmp: print(j,end = ' ') print() print(lst[i])