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

矩阵乘法计算量估算

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

while 1:

    try:
        n = int(input())

        matrix_row_col = [[0]*2 for _ in range(n)]

        matrix_name = []

        for i in range(n):
            matrix_name.append(chr(ord('A') + i))


        for i in range(n):
            matrix_row_col[i] = list(map(int, input().split()))

        evalution = list(input())

        Stack = []

        num = 0

        for c in evalution:
            if c == '(':
                continue
            elif c.isalpha():
                Stack.append(matrix_row_col[matrix_name.index(c)])
            elif c == ')':
                b_data = Stack.pop()
                a_data = Stack.pop()
                
                num = num + a_data[0] * a_data[1] * b_data[1]
                Stack.append([a_data[0], b_data[1]])
        print(num)

    except:
        break

全部评论

相关推荐

头像
11-09 17:30
门头沟学院 Java
TYUT太摆金星:我也是,好几个华为的社招找我了
点赞 评论 收藏
分享
我即大橘:耐泡王
点赞 评论 收藏
分享
点赞 收藏 评论
分享
牛客网
牛客企业服务