Topic 1001:a+b for matrices

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.