题解 | MP3光标位置

MP3光标位置

https://www.nowcoder.com/practice/eaf5b886bd6645dd9cfb5406f3753e15

import sys

count = int(input())
s = input()

cursor_pos = 0#记录光标位置
index = 0#记录当前歌曲

for j in s:
    if j == "U":
        # 光标在第一首歌曲的情况
        if cursor_pos == 0:
            if index == 0:
                cursor_pos = 3
        else:
            cursor_pos = cursor_pos - 1
        index = index - 1
        if index < 0:
            index = count - 1

    elif j == "D":
        # 光标在最后一首歌曲的情况
        if cursor_pos == 3:
            if index == count-1:
                cursor_pos = 0
        else:
            cursor_pos = cursor_pos + 1
        index = (index + 1) % count

start = index + 1 - cursor_pos
for i in range(start, start + 3):
    if i >0:
        print(i, end=" ")

print(start + 3)
print(index + 1)

全部评论

相关推荐

码农索隆:《211》《转正4k》😂,真给我整笑了
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务