python
矩阵乘法
http://www.nowcoder.com/questionTerminal/ebe941260f8c4210aa8c17e99cbc663b
''' 思路: 根据输入构建二位数组A、B来代表两个矩阵 [x*y] * [y:z] = [x*z————用res构建一个x行z列的矩阵[[0 for x in range(z)] for x in range(x) 计算矩阵,遍历行x、遍历列z,遍历元素下标y 根据矩阵计算方法,第i行第j列的结果就是res[i][j] += A[i][k]*B[k][j] 累加计算对应位置的值 打印输出res ''' while True: try: x = int(input()) y = int(input()) z = int(input()) A,B = [],[] res = [[0 for x in range(z)] for x in range(x)] for i in range(x): A += [list(map(int,input().split()))] for i in range(y): B += [list(map(int,input().split()))] for i in range(x): for j in range(z): for k in range(y): res[i][j] += A[i][k]*B[k][j] for x in res: print(*x) except: break