import sys
def matrixAdd(matrixA,matrixB,row,column):
rst = [[0 for c in range(column)] for r in range(row)]
rstT = [[0 for c in range(row)] for r in range(column)]
for c in range(column):
for r in range(row):
temp = matrixA[r][c] + matrixB[r][c]
rst[r][c],rstT[c][r] = temp,temp
return rst,rstT
newCase, countLine = True, 0
for line in sys.stdin:
line = line.strip()
if newCase:
if line == '0':
break
newCase = False
M, N = map(int, line.split())
countLine = 2 * M
ls = list()
else:
ls.append(list(map(int, line.split())))
countLine -= 1
if countLine == 0:
zero_cnt = 0
matrixA, matrixB = ls[:M], ls[M:]
rst,rstT = matrixAdd(matrixA,matrixB,M,N)
for item in rst:
if set(item) == set([0]):
zero_cnt += 1
for item in rstT:
if set(item) == set([0]):
zero_cnt += 1
print(zero_cnt)
newCase = True
KY153 A+B for Matrices
最新推荐文章于 2024-11-11 21:30:41 发布