题解 | #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







全部评论

相关推荐

06-17 21:57
门头沟学院 Java
白友:噗嗤,我发现有些人事就爱发这些,明明已读不回就行了,就是要恶心人
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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