题解 | #MP3光标位置#

MP3光标位置

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

while 1:
    try:
        n = int(input())
        s = list(input())

        song_list = []

        now_page = []

        for i in range(1, n + 1):
            song_list.append(i)
            if n <= 4:
                now_page.append(i)
            else:
                now_page = [1, 2, 3, 4]
        now_song = 1
        
        for i in range(len(s)):
            action = s[i]

            if action == 'U':
                if now_song == 1:
                    now_song = song_list[n - 1]
                    if n > 4:
                        now_page = [n - 3, n - 2, n - 1, n]
                
                elif n > 4 and now_song == now_page[0] and now_song != 1:
                    del now_page[3]
                    now_page.insert(0, now_song - 1)
                    now_song = now_page[0]

                else:
                    now_song = now_song - 1

            if action == 'D':
                if now_song == song_list[n - 1]:
                    now_song = 1
                    if n > 4:
                        now_page = [1, 2, 3, 4]

                elif n > 4 and now_song == now_page[3] and now_song != song_list[n - 1]:
                    del now_page[0]
                    now_page.append(now_song + 1)
                    now_song = now_page[3]

                else:
                    now_song = now_song + 1

        for i in now_page:
            print(i, end=' ')
        print()
        print(now_song)

    except:
        break

全部评论

相关推荐

与火:这不接? 留子的钱不挣白不挣
点赞 评论 收藏
分享
点赞 收藏 评论
分享
牛客网
牛客企业服务