2013
12-13

# 九度-1001-A+B for Matrices

### 题目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.

2 2
1 1
1 1
-1 -1
10 9
2 3
1 2 3
4 5 6
-1 -2 -3
-4 -5 -6
0

1
5

#include <stdio.h>
#include <string.h>

#define M 12

int matrix[2][M][M];
int res[M + M];

int main(int argc, char **argv)
{
int i, j, m, n, nresult;

while (EOF != scanf("%d", &m) && m)
{
memset(res, 0, sizeof(res));
nresult = 0;
scanf("%d", &n);
for (i = 0; i < m; ++i)
{
for (j = 0; j < n; ++j)
{
scanf("%d", &matrix[0][i][j]);
}
}
for (i = 0; i < m; ++i)
{
for (j = 0; j < n; ++j)
{
scanf("%d", &matrix[1][i][j]);
matrix[1][i][j] += matrix[0][i][j];
if (matrix[1][i][j])
{
res[i] = res[m + j] = 1;
}
}
}
for (i = 0; i < m + n; ++i)
{
if (!res[i])
{
++nresult;
}
}
printf("%d\n", nresult);
}
return 0;
}

1. 这道题目的核心一句话是：取还是不取。
如果当前取，则index+1作为参数。如果当前不取，则任用index作为参数。

2. Excellent Web-site! I required to ask if I might webpages and use a component of the net web website and use a number of factors for just about any faculty process. Please notify me through email regardless of whether that would be excellent. Many thanks