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

矩阵乘法计算量估算

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)


全部评论

相关推荐

不要停下啊:大二打开牛客,你有机会开卷了,卷起来,去找课程学习,在牛客上看看大家面试笔试都需要会什么,岗位有什么需求就去学什么,努力的人就一定会有收获,这句话从来都经得起考验,像我现在大三了啥也不会,被迫强行考研,炼狱难度开局,啥也不会,找工作没希望了,考研有丝丝机会
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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