题解 | #MP3光标位置#

MP3光标位置

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

class MP3_screen(object):

    def __init__(self, song_count):
        self.song_list = [x for x in range(1, song_count + 1)]
        self.show = self.song_list[:4]
        self.pivot = 1

    def up(self):
        if self.pivot == 1:
            self.pivot = len(self.song_list)
            self.show = self.song_list[len(self.song_list) - 4:]
        else:
            self.pivot -= 1
            if self.pivot not in self.show:
                self.show = self.song_list[self.pivot - 1: self.pivot + 3]

    def down(self):
        if self.pivot == len(self.song_list):
            self.pivot = 1
            self.show = self.song_list[:4]
        else:
            self.pivot += 1
            if self.pivot not in self.show:
                self.show = self.song_list[self.pivot - 4: self.pivot]


mp3_screen = MP3_screen(int(input()))
commands = input().upper()

for com in commands:
    if com == 'U':
        mp3_screen.up()
    if com == 'D':
        mp3_screen.down()

print(" ".join(map(str, mp3_screen.show)))
print(mp3_screen.pivot)


全部评论

相关推荐

点赞 收藏 评论
分享
牛客网
牛客企业服务