首页 > 试题广场 >

A+B for Matrices

[编程题]A+B for Matrices
  • 热度指数:5545 时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 64M,其他语言128M
  • 算法知识视频讲解
    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.
示例1

输入

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
头像 wbc990512
发表于 2021-01-28 16:11:40
题意:给出两个同型矩阵A,B(行列数在每组数据第一行给出),判断矩阵A+B全0行和全0列共有多少个人思路:用三次二重循环:第一次读矩阵A;第二次按行优先读矩阵B,同时判断每个元素是否和A对应位置的元素互为相反数(通过flag标记)。第三次按列优先判断A和B的每一对应列。 #include<s 展开全文
头像 求求offer的土拨鼠很无聊
发表于 2023-03-03 14:53:56
#include <iostream> using namespace std; int main() { int m,n; while(cin>>m>>n && m!=0){ int a[m][n]; int b 展开全文
头像 wslcccc
发表于 2024-03-20 20:27:42
while True: try: l1=list(map(int,input().strip().split())) a=l1[0] if a==0: continue b=l1[1] l 展开全文
头像 XwwwwL
发表于 2023-03-07 19:54:55
#include <iostream> using namespace std; struct Matrix { int matrix[10][10]; int row, col;//行列 Matrix(int r, int c) { row 展开全文
头像 牛客7777779号
发表于 2023-03-10 20:48:14
#include <iostream> #include <cstring> #include <algorithm> #include <math.h> #include <stdlib.h> using namespace std; 展开全文
头像 西区梭梭树
发表于 2023-03-09 10:56:12
#include <iostream> using namespace std; struct matrix { int data[10][10]; int row; int col; matrix(int r, int c) { row 展开全文
头像 Huster水仙
发表于 2023-01-16 21:28:01
#include<iostream> using namespace std; const int Maxn=10; struct Matrix{ int matrix[Maxn][Maxn]; int row,col; Matrix(){}; Matr 展开全文
头像 bigbigcake
发表于 2024-03-20 09:52:48
#include <iostream> using namespace std; int main() { int m, n; while (cin >> m) { if(m==0)break; cin>>n; 展开全文
头像 天乔巴夏、
发表于 2022-01-14 03:36:17
#include<iostream> using namespace std; int nums[105][105]; int main() { int m, n; while(cin >> m >> n) { for 展开全文
头像 苇岸弦歌
发表于 2023-02-20 12:16:48
遍历方法数全零行和全零列,通过flag标记,遇到非零元素将标记置为false,并直接结束本轮循环 #include <cmath> #include <iostream> using namespace std; struct matrix { int m[10][1 展开全文