矩阵乘法
程序员文章站
2022-07-12 09:07:27
...
# -*- coding:utf -*-
# 矩阵乘法
import sys
while True:
try:
x = int(sys.stdin.readline().strip('\n'))
y = int(sys.stdin.readline().strip('\n'))
z = int(sys.stdin.readline().strip('\n'))
a, b = [], []
c = [[] for i in range(x)]
# get input
for i in range(x):
a.append(map(int, sys.stdin.readline().strip('\n').split()))
for i in range(y):
b.append(map(int, sys.stdin.readline().strip('\n').split()))
# calculate
for i in range(x):
for j in range(z):
s = 0
for k in range(y):
s += a[i][k] * b[k][j]
c[i].append(s)
# ouput
print '\n'.join([' '.join([str(j) for j in i]) for i in c])
except:
break