题解 | #矩阵乘法#

矩阵乘法

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

x = int(input())
y = int(input())
z = int(input())

A = []  # x行y列
B = []  # y行z列 
C = [[0 for j in range(z)]for i in range(x)]    # x行z列

# 输入A矩阵
for i in range(x):
    A.append(list(map(int,input().split())))
# 输入B矩阵
for j in range(y):
    B.append(list(map(int,input().split())))

# 计算C矩阵
for i in range(x):
    for k in range(z):
        sum = 0
        for j in range(y):
            sum += A[i][j] * B[j][k]
            C[i][k] = sum
for i in C:
    for j in i:
        print(j,end=' ')
    print()

全部评论

相关推荐

头顶尖尖的程序员:我也是面了三四次才放平心态的。准备好自我介绍,不一定要背熟,可以记事本写下来读。全程控制语速,所有问题都先思考几秒,不要急着答,不要打断面试官说话。
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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