题解 | 舞萌时间到!

舞萌时间到!

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

#格式化输入
s = input()
q = int(input())
#字符数值字典,前缀和数组初始化
dx = dict(zip(['P','p','G','g','m'],[3,2,1,0,0]))
ans, dp = 0, []
for c in s:
    ans += dx[c]
    dp.append(ans)
#输出结果
for _ in range(q):
    l, r = map(int,input().split())
    if l==1:
        print(dp[r-1])
    else:
        print(dp[r-1]-dp[l-2])

全部评论

相关推荐

评论
点赞
收藏
分享

创作者周榜

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