题目1001:A+B for Matrices
??? This time, you are supposed to find A+B where A and B are two matrices, and then count the number of zero rows and columns.
??? The input consists of several test cases, each starts with a pair of positive integers M and N (≤10) which are the number of rows and columns of the matrices, respectively. Then 2*M lines follow, each contains N integers in [-100, 100], separated by a space. The first M lines correspond to the elements of A and the second M lines to that of B.
??? The input is terminated by a zero M and that case must NOT be processed.
??? For each test case you should output in one line the total number of zero rows and columns of A+B.
5
思路: 用輔助空間在第二個矩陣輸入的同時計算對應位置的和,并且計算 i行 和 j列的對應的累加值。最后掃描,得到行列值為0的元素的個數。
code:
總結
以上是生活随笔為你收集整理的题目1001:A+B for Matrices的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: mysql排行榜sql的实现
- 下一篇: vc:如何从Internet上有效而稳定