题解 | #密码验证合格程序#
MP3光标位置
http://www.nowcoder.com/practice/eaf5b886bd6645dd9cfb5406f3753e15
import sys def seek_music(music_position, page_position, command): # 上翻 音乐相对于页面的位置 页面第一个音乐的位置(绝对) if command == "U": # 在第一首歌曲 if music_position == 1 and page_position == 1: page_position = music_number - 3 if music_number > 4 else 1 music_position = 4 if music_number > 4 else music_number elif music_position == 1 and page_position > 1: page_position -= 1 else: music_position -= 1 elif command == "D": # 最后一首歌曲下翻 if music_position + page_position - 1 == music_number: music_position = 1 page_position = 1 # 当页最后一首 elif music_position == 4: page_position += 1 else: music_position += 1 return music_position, page_position input_sequence = 0 for line in sys.stdin: music_position, page_position = 1, 1 input_sequence += 1 commands = line.strip() if input_sequence % 2 == 1: music_number = int(commands) continue for command in commands: music_position, page_position = seek_music(music_position, page_position, command) # print(command, music_position, page_position) for i in range(4): if page_position + i <= music_number: print(page_position + i, end=' ') print() print(page_position + music_position -1)