题解 | #MP3光标位置#Python解法
MP3光标位置
http://www.nowcoder.com/practice/eaf5b886bd6645dd9cfb5406f3753e15
def solve(n, ops): choose = 1 head = 1 #不需要记录当前列表,只需记录当前的表头 for op in ops: if op == 'U': if n > 4 and choose == head: head = head - 1 if head > 1 else n - 3 choose = choose - 1 if choose > 1 else n elif op == 'D': if n > 4 and choose == head + 3: head = head + 1 if choose < n else 1 choose = choose + 1 if choose < n else 1 return [i for i in range(head, head + min(4, n))], choose while True: try: n = int(input()) ops = input() show_list, choose = solve(n, ops) print(' '.join(str(i) for i in show_list)) print(choose) except: break