Title 1001:a+b for matrices
Time limit:1 seconds memory limit:
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 (≤) which AR E 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 2
1 1
1 1
-1-1
10 9
2 3
1 2 3
4 5 6
-1-2-3
-4-5-6
0
Sample output:
1
5
----------------
The code has a bugand the test data is not rigorous . AC ... .
----------------------------------------------------
ImportJava.util.Scanner; Public classMain { Public Static voidMain (string[] args) {//TODO auto-generated Method StubScanner sc=NewScanner (system.in); while(Sc.hasnext ()) {intm=Sc.nextint (); if(m==0) Break; intn=Sc.nextint (); inta[][]=New int[M][n]; intb[][]=New int[M][n]; intc[][]=New int[M][n]; intZorerow=0; intZorecol=0; for(inti=0;i<m;i++) for(intj=0;j<n;j++) A[i][j]=Sc.nextint (); for(inti=0;i<m;i++) for(intj=0;j<n;j++) {B[i][j]=Sc.nextint (); C[I][J]=a[i][j]+B[i][j]; } intTemp=0; intTmp=0; for(inti=0;i<m;i++){ for(intj=0;j<n;j++) {Temp+=C[i][j]; } if(temp==0) zorerow++; Temp=0; } for(intj=0;j<n;j++){ for(inti=0;i<m;i++) {tmp+=C[i][j]; } if(tmp==0) zorerow++; TMP=0; } System.out.println (Zorerow+Zorecol); } }}
Topic 1001:a+b for matrices