日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

题目1001:A+B for Matrices

發布時間:2025/3/15 编程问答 20 豆豆
生活随笔 收集整理的這篇文章主要介紹了 题目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

思路: 用輔助空間在第二個矩陣輸入的同時計算對應位置的和,并且計算 i行 和 j列的對應的累加值。最后掃描,得到行列值為0的元素的個數。


code:

#include <bits/stdc++.h>using namespace std;int main(){int a[100][100] ;int m , n ;while (cin>>m && m!=0){cin>>n;for (int i = 0 ; i < m ; ++i){a[i][n] = 0 ;for (int j = 0 ; j <n ; ++j){a[m][j] = 0 ;cin>>a[i][j];}}int t ;for (int i = 0 ; i < m ; ++i){for (int j = 0 ; j <n ; ++j){cin>>t;a[i][j]+=t;a[i][n]+=a[i][j] ;a[m][j]+=a[i][j];}}int sum = 0;for (int i = 0 ; i < m ;++i)if (a[i][n] == 0 ) sum++;for (int j = 0 ; j < n ;++j)if (a[m][j] == 0 ) sum++;cout<<sum<<endl ;}return 0; }

總結

以上是生活随笔為你收集整理的题目1001:A+B for Matrices的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。