python3 PTA1040 有几个PAT (3号测试点超时)(21/25分)

str_0 = input()
N = 0
while 1:
    p = str_0.find('P')
    if p == -1:
        break
    P_num = 1
    while p < len(str_0) -1 and str_0[p+1] == 'P':
        p += 1
        P_num += 1
    T = str_0[p + 1:].find('T')
    t = T + len(str_0[:p + 1])
    n = 0
    while T != -1 and t < len(str_0):
        T_num = 1
        while t < len(str_0) - 1 and str_0[t+1] == 'T':
            t += 1
            T_num += 1
        A_num = str_0[p:t].count('A')
        n += T_num * A_num
        t += 1
        T = str_0[t:].find('T')
        t = T + len(str_0[:t])
    N += n*P_num
    str_0 = str_0[p+1:]

print(N % 1000000007)
发布了84 篇原创文章 · 获赞 10 · 访问量 8552

猜你喜欢

转载自blog.csdn.net/AK47red/article/details/104418001