题解 | #MP3光标位置#

MP3光标位置

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

n =int(input())
m =input()
s =[i for i in range(1,n+1)]
idx=0
st=0
ed=4
if n <=4:
    idx=(m.count('D')-m.count('U')+abs(m.count('D')-m.count('U'))*n)%n
    st=0
    ed=4
    
else:
    for i in m:
        if i=='U':
            idx-=1
            if idx<0:
                idx+=n
                st=n-4
                ed=n
                continue
            if idx>=st:
                continue
            else:
                st -=1
                ed -=1
        if i =='D':
            idx +=1
            if idx>=n:
                idx -=n
                st=0
                ed=4
                continue
            if idx< ed:
                continue
            else:
                st +=1
                ed +=1
k=s[st:ed]
print(' '.join(list(map(str,k))))
print(s[idx])

全部评论

相关推荐

菠落蜜:这个是系统自动投的,不是hr主动打招呼。更抽象的还有ai回复
我的秋招日记
点赞 评论 收藏
分享
09-19 13:59
门头沟学院 Java
用微笑面对困难:Trae一下,如果真成了,他用了直接发字节起诉代码版权,,这个代码不商用是没问题的如果没成也是情理之中的。
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务