题解 | #矩阵乘法#
矩阵乘法
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()