题解 | #MP3光标位置#

MP3光标位置

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

while True:
    try:
        s1 = int(input())
        s2 = list(input())
        dic = {'U': -1, 'D': 1}
        res = []
        num = 1
        flag = 0
        if s1 <= 4:
            flag = 1
            for i in range(1, s1+1):
                res.append(i)
        if flag == 1:
            print(' '.join(str(i) for i in res))
            for s in s2:
                num += dic[s]
                if num == 0:
                    num = s1
                elif num == s1+1:
                    num = 1
            print(num)
        if s1>4:
            flag=2
        first=1
        end=4
        if flag==2:
            for k in range(len(s2)):
                num +=dic[s2[k]]
                if num==0:#向上突破1
                    num=s1
                    first=s1-3
                    end=s1
                elif num ==s1+1:#向下突破底
                    num=1
                    first=1
                    end=4
                elif num<=end and num >=first:#在first和end中移动,不变
                    continue
                elif num==first-1:#突破first
                    first=first-1
                    end=end-1
                elif num==end+1:#突破end
                    first=first+1
                    end=end+1
            res2=[y for y in range(first,end+1)]
            print(' '.join(str(l) for l in res2))
            print(num)#输出
    except:
        break
全部评论

相关推荐

10-13 17:47
门头沟学院 Java
wulala.god:图一那个善我面过,老板网上找的题库面的
点赞 评论 收藏
分享
头像
09-29 16:18
门头沟学院 Java
点赞 评论 收藏
分享
2 收藏 评论
分享
牛客网
牛客企业服务