1:光标初始位置是1
2:歌曲数量大于4才会出现翻页的操作
3:翻页后光标还在第一个位置(向上翻)或第四个位置(向下翻)
while 1:
try:
n = int(input())
action = input()
cursor = 1
screen = []
for i in range(1,n+1):
if i > 4:
break #当歌曲数量大于4时,screen初始状态为[1,2,3,4]
screen.append(i)#定义一个列表screen,当歌曲数量小于4,len(screen)=n, else: len(screen)=4
for i in action:
if i == 'U':
cursor = cursor - 1
if cursor == 0:#当向上翻到头时
cursor = n#光标指到最后一首歌
if n > 4:
screen = [n-3,n-2,n-1,n]#屏幕变成最后四首歌
if cursor not in screen:
screen.insert(0,cursor)#屏幕随着光标往上翻页
screen.pop(4)
if i == "D":
cursor = cursor + 1
if cursor > n:#当向下翻到头时
cursor = 1
if n > 4:
screen = [1,2,3,4]#屏幕变成最初四首歌
if cursor not in screen:
screen.append(cursor)#屏幕随着光标向下翻页
screen.pop(0)
print(" ".join(list(map(str,screen))))
print(cursor)
except:
break