题解 | #MP3光标位置#

MP3光标位置

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

import sys

while True:
    try:
        n = int(input().strip())
        command = list(input().strip())
        b = [i for i in range(1,n+1)]
        a =[1,2,3,4]
        fla=1
        dirct=1
        for i in range(len(command)):
            if command[i] == 'U':
                fla-=1
                if fla not in a:
                    if fla < 1:
                        a =b[-4:]
                        fla= b[-1]
                    else:
                        a=[i for i in range(fla,fla+4)]
            if command[i] == 'D':
                fla+=1
                if fla not in a:
                    if fla > n:
                        a = b[0:4]
                        fla = b[0]
                    else:
                        a=[i for i in range(fla-3,fla+1)]
        res = str(fla)
        a= list(map(str,a))
        print(' '.join(a)+'\n'+res)

    except:
        break

全部评论

相关推荐

评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客企业服务