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<math.h> int main() { int m,n,i,j,ans; int a[10][10],b; while(scanf("%d",&m)!=EOF&&m) { ans=0; scanf("%d",&n); for(i=0;i<m;++i) { for(j=0;j<n;++j) { scanf("%d",&a[i][j]); } } for(i=0;i<m;++i) { for(j=0;j<n;++j) { scanf("%d",&b); a[i][j]+=b; } } for(i=0;i<m;++i) { for(j=0;j<n;++j) { if(a[i][j]!=0) break; } if(j==n) ++ans; } for(i=0;i<n;++i) { for(j=0;j<m;++j) { if(a[j][i]!=0)//注意是a[j][i]不是a[i][j] break; } if(j==m) ++ans; } printf("%d\n",ans); } }
相關推薦
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 inpu
A+B for Matrices(JAVA)
題目描述: 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. 輸入
題解報告:hdu 1002 A + B Problem II(大數加法)
return 大數類 class family HERE contains urn integer ons Problem Description I have a very simple problem for you. Given two integers A and
1002 A+B for Polynomials (25 分)
This time, you are supposed to find A+B where A and B are two polynomials. Input Specification: Each input file contains one test case. Each
PAT 甲級 1002 A+B for Polynomials (25 分)
1002 A+B for Polynomials (25 分) This time, you are supposed to find A+B where A and B are two polynomials.
PAT 1002 A+B for Polynomials (25 分)Java實現
1. 題意 給兩個多項式,把它們加起來 樣例分析: A多項式 2 1 2.4 0 3.2 第一個2指得是2個非0係數項 然後的兩個數,1是項數,2.4是係數 最後兩個數,0是項數,3.2是係數 所以就有f(x) = 2.4x + 3.2 B多項式 2 2 1.5 1 0.5 f(x)
PAT (Advanced Level) Practice 1002 A+B for Polynomials (25 分)
This time, you are supposed to find A+B where A and B are two polynomials. Input Specification: Each input file contains one test case. Each case
pat1002 甲級 A+B for Polynomials (25 分)
This time, you are supposed to find A+B where A and B are two polynomials. Input Specification: Each input file contains one test case.
PAT (Advanced Level) 1002 A+B for Polynomials (25 分)
1002 A+B for Polynomials (25 分) This time, you are supposed to find A+B where A and B are two polynomials. Input Specification: Each input
1002 A+B for Polynomials (25 分)(簡單的PAT甲級題目)
我要考甲級!!! This time, you are supposed to find A+B where A and B are two polynomials. Input Specification: Each input file contains one t
PAT (Advanced Level) Practice 1002 A+B for Polynomials (25 分)(C++)(甲級)
1002 A+B for Polynomials (25 分) This time, you are supposed to find A+B where A and B are two polynomials. Input Specification: Each input
洛谷 P2421 A-B數對(增強版)
clas pla back www pro fff 分答 left ins P2421 A-B數對(增強版) 題目背景 woshiren在洛谷刷題,感覺第一題:求兩數的和(A+B Problem)太無聊了,於是增加了一題:A-B Pro
洛谷——P2421 A-B數對(增強版)
++ 可能 復制 fin radi 輸入輸出格式 個數 -c () 題目背景 woshiren在洛谷刷題,感覺第一題:求兩數的和(A+B Problem)太無聊了,於是增加了一題:A-B Problem,難倒了一群小朋友,哈哈。 題目描述 給出N 個從小到大排好序的整
【PAT】B1011 A+B和C(15 分)
can scan ++ i++ clu return ret cas n) #include<stdio.h> int main() { int n; scanf("%d",&n); for(int i=1;i<=n;i+
1011 A+B 和 C (15 分)
#include <iostream> using namespace std; int main() { long long a,b,c; int n; int i=0; cin>>n; while(n--){ c
A+B for Matrices
1.題目描述 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
PAT 1065 A+B and C (20 分)Java實現
題意: 計算A+B是否大於C 思路: 用Java做很容易,可以直接用大數類,就不用模擬了~~ 程式碼: package adv1065; import java.io.BufferedReader; import java.io.IOException; impor
PAT-乙-1011 1011 A+B 和 C (15 分)
程式碼(java) import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(Syst
1011 A+B 和 C (15 分)
給定區間 [−231,231] 內的 3 個整數 A、B 和 C,請判斷 A+B 是否大於 C。 輸入格式: 輸入第 1 行給出正整數 T (≤10),是測試用例的個數。隨後給出
PAT 1058 A+B in Hogwarts (20 分)
1058 A+B in Hogwarts (20 分) If you are a fan of Harry Potter, you would know the world of magic has its own currency system – as Ha