题解 | #MP3光标位置#

MP3光标位置

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

#按照提示写逻辑即可
import sys
while True:
    try:
        N = int(input())
        l = [i for i in range(1, N + 1)]
        g_index = 1
        s = l[g_index - 1:4]
        orders = input()
#         print(l, orders,s)
        if N <= 4:
            for o in orders:
                if o == 'U':
                    if g_index == 1:
                        g_index = N
                    else:
                        g_index -= 1
                else:
                    if g_index == N:
                        g_index = 1
                    else:
                        g_index += 1
        else:
            for o in orders:
                if o == 'U':
                    if g_index == 1:
                        g_index = N
                        s = l[g_index - 4:g_index]
                    elif l[g_index - 1] == s[0]:
                        g_index -= 1
                        s = l[g_index - 1:g_index + 3]
                    else:
                        g_index -= 1
                else:
                    if g_index == N:
                        g_index = 1
                        s = l[g_index - 1:g_index + 3]
                    elif l[g_index - 1] == s[3]:
                        g_index += 1
                        s = l[g_index - 4:g_index]
                    else:
                        g_index += 1
        print(" ".join(map(str,s)))
        print(g_index)

    except:
#         print(sys.exc_info())
        break







全部评论

相关推荐

牛客你可姐:也不要一味的看公司人数决定工作,比如我前司只有30人,但是已经创立了10年……
点赞 评论 收藏
分享
MrGaomq:你沟通的太少了,我两个号沟通了都1w多了
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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