-
Title Description:
-
This is supposed to find a+b where A and B are both matrices, and then count the number of zero rows and columns .
-
Input:
-
The input consists of several test cases, each starts with a pair of positive integers M and N (≤10) which is the number of rows and columns of the matrices, respectively. Then 2*m lines follow, each contains N integers in [ -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 being processed.
-
Output:
-
For each test case, you should output on one line, the total number of zero rows and columns of a+b.
-
Sample input:
-
2 21 11 1-1-110 92 31 2 34 5 6-1 -2-3-4-5-60
-
Sample output:
-
15
Here is the simplest solution, but the complexity of the program itself is not high, so you can pass:
1 ImportJava.util.Scanner;2 3 Public classmain{4 Public Static voidMain (string[] args) {5Scanner in=NewScanner (system.in);6 intM,n;7m=in.nextint ();8 while(m!=0){9n=in.nextint ();Ten in.nextline (); One int[][]a=New int[m][n]; A int[][]b=New int[m][n]; - for(inti=0;i<m;i++){ - for(intj=0;j<n;j++){ thea[i][j]=in.nextint (); - } - in.nextline (); - } + for(inti=0;i<m;i++){ - for(intj=0;j<n;j++){ +B[i][j]=in.nextint () +A[i][j]; A } at in.nextline (); - } - intCout=0; - for(inti=0;i<m;i++){ - Booleando{true; - for(intj=0;j<n;j++){ in if(b[i][j]!=0) -do{false; to } + if(bo) -cout++; the } * for(inti=0;i<n;i++){ $ Booleando{true;Panax Notoginseng for(intj=0;j<m;j++){ - if(b[j][i]!=0) thedo{false; + } A if(bo) thecout++; + } - System.out.println (cout); $m=in.nextint (); $ } - } - } the /************************************************************** - problem:1001Wuyi user:0000h the Language:java - result:accepted Wu time:930 Ms - memory:18872 KB About ****************************************************************/
Topic 1001:a+b for matrices