题解 | #MP3光标位置#
MP3光标位置
https://www.nowcoder.com/practice/eaf5b886bd6645dd9cfb5406f3753e15
指令只有两种,在两种指令下,根据光标的位置做进一步的判断就好
不管是那种指令,光标只有两种位置需要对显示列表进行调整,
在up的指令下,光标在第一首歌和列表的第一首歌时,需要对列表进行调整,其他情况下只需要修改index即可
down指令亦然
n = int(input())
comm = input()
mu_list = [i for i in range(n+1)]
start = 1
end = 4 if n >=4 else n
index = 1
for co in comm:
if co == 'U':
if index == 1:
start = n - 3 if n-3 > 0 else 1
end = n
index = n
elif index == start:
start -= 1
end -= 1
index -= 1
else:
index -=1
if co == 'D':
if index == n:
start = 1
end = 4 if n >= 4 else n
index = 1
elif index == end:
start += 1
end += 1
index += 1
else:
index +=1
print(' '.join(str(i) for i in range(start,end+1)))
print(index)
