题解 | #矩阵乘法#

矩阵乘法

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

while True:
    try:
        n = int(input())
        m = int(input())
        k = int(input())
        list1 = []
        list2 = []
        for i in range(n):
            list1.append(list(map(int, input().split(' '))))
        for j in range(m):
            list2.append(list(map(int, input().split(' '))))
        list3 = []
        for v in range(k):
            temp = []
            for x in list2:
                temp.append(x[v])
            list3.append(temp)
        # print(list1)
        # print(list2)
        # print(list3)
        for i in list1:
            result = []
            for j in list3:
                numbers = []
                for x, y in zip(i, j):
                    numbers.append(x*y)
                result.append(str(sum(numbers)))
            print(' '.join(result))

    except:
        break

全部评论

相关推荐

点赞 评论 收藏
分享
07-01 13:37
门头沟学院 Java
steelhead:不是你的问题,这是社会的问题。
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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