题解 | #矩阵乘法#

矩阵乘法

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

import sys
firsthang = int(input().strip())
firstlie = secondhang = int(input().strip())
secondlie = int(input().strip())
count1,矩阵1,矩阵2 = 0,[],[]
for line in sys.stdin:
    count1 +=1
    tamp = list(map(int,line.strip().split(" ")))
    if count1 <= firsthang:
        矩阵1.append(tamp)
    else:
        矩阵2.append(tamp)
relist = [[0]*secondlie for _ in range(firsthang)]
for i in range(firsthang):
    for j in range(secondlie):
        tamp = 0
        for k in range(firstlie):
            tamp += 矩阵1[i][k] * 矩阵2[k][j] 
        relist[i][j] = tamp
for i in relist:
    for k in i:
        print(k,end=" ")
    print()

全部评论

相关推荐

07-18 13:49
门头沟学院 Java
26小林不会梦到感谢...:这个点还在面暑期嘛不是马上开秋招了
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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