题解 | #MP3光标位置#Python解法

MP3光标位置

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

def solve(n, ops):
    choose = 1
    head = 1 #不需要记录当前列表,只需记录当前的表头
    for op in ops:
        if op == 'U':
            if n > 4 and choose == head:
                head = head - 1 if head > 1 else n - 3
            choose = choose - 1 if choose > 1 else n
        elif op == 'D':
            if n > 4 and choose == head + 3:
                head = head + 1 if choose < n else 1
            choose = choose + 1 if choose < n else 1
    return [i for i in range(head, head + min(4, n))], choose


while True:
    try:
        n = int(input())
        ops = input()
        show_list, choose = solve(n, ops)
        print(' '.join(str(i) for i in show_list))
        print(choose)
    except:
        break
全部评论

相关推荐

菜鸡29号:根据已有信息能初步得出以下几点: 1、硕士排了大本和大专 2、要求会多语言要么是招人很挑剔要么就是干的活杂 3、给出校招薪资范围过于巨大,说明里面的薪资制度(包括涨薪)可能有大坑
点赞 评论 收藏
分享
牛可乐121381:卖课的
点赞 评论 收藏
分享
评论
1
收藏
分享

创作者周榜

更多
牛客网
牛客企业服务