题解 | #矩阵乘法计算量估算#

矩阵乘法计算量估算

https://www.nowcoder.com/practice/15e41630514445719a942e004edc0a5b

import string
num = int(input().strip())
list1,table1,resault = [],{},0
def jisuan(a,b):
    global resault
    resault += a[0]*a[1]*b[1]
    return [a[0],b[1]]
for i in range(num):
    a = list(map(int,input().strip().split(" ")))
    list1.append(a)
for i in string.ascii_uppercase:
    try:
        table1[i] = list1.pop(0)
    except:
        break
str1 = input().strip()
while str1.count(")") >= 1:
    index1 = str1.find(")")
    tamp1 = jisuan(table1[str1[index1-2]],table1[str1[index1-1]])
    table1[str1[index1-2]] = tamp1
    str1 = str1[0:index1-3]+str1[index1-2]+str1[index1+1:]
print(resault)


全部评论

相关推荐

勇敢牛牛不怕困难,希望能过初筛
投递韶音科技等公司10个岗位
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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