题解 | #MP3光标位置#

MP3光标位置

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

def ud(s):
    if s=="U":
        return -1
    else:
        return 1
num=int(input())
s=input()
totsong=[i for i in range(1,num+1)]
site=0
lssong=[]
if num<=4:
    lssong=totsong
    for x in s:
        site=(site+ud(x))%num
else:
    lssong=totsong[:4]
    for x in s:
        site=(site+ud(x))%num
        if site==num-1:
            lssong=totsong[num-4:]
        elif site==0:
            lssong=totsong[:4]
        elif totsong[site] not in lssong:
            if x=="U":
                lssong=totsong[site:site+4]
            else:
                lssong=totsong[site-3:site+1]
print(" ".join(map(lambda x:str(x),lssong)))
print(site+1)












全部评论

相关推荐

微风不断:兄弟,你把四旋翼都做出来了那个挺难的吧
点赞 评论 收藏
分享
评论
点赞
收藏
分享
牛客网
牛客企业服务