博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
A+B for Matrices
阅读量:7103 次
发布时间:2019-06-28

本文共 1999 字,大约阅读时间需要 6 分钟。

 

时间限制:1 秒

内存限制:32 兆

特殊判题:

提交:4483

解决:1938

题目描述:

    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 21 11 1-1 -110 92 31 2 34 5 6-1 -2 -3-4 -5 -60
样例输出:
15

 

1 #include 
2 #include
3 #include
4 #include
5 #include
6 #include
7 8 #include
9 #include
10 #include
11 #include
12 #include
13 #include
14 #include
15 #include
16 #include
17 18 using namespace std; 19 20 21 int a[14][14]; 22 int b[14][14]; 23 24 25 26 int main() 27 { 28 29 30 31 32 int m,n; 33 34 int i,j,k; 35 36 while(scanf("%d",&m)!=EOF) 37 { 38 if(m==0) 39 break; 40 41 scanf("%d",&n); 42 43 for(i=1;i<=m;i++) 44 { 45 for(j=1;j<=n;j++) 46 { 47 scanf("%d",&a[i][j]); 48 } 49 } 50 51 52 for(i=1;i<=m;i++) 53 { 54 for(j=1;j<=n;j++) 55 { 56 scanf("%d",&b[i][j]); 57 } 58 } 59 60 61 62 for(i=1;i<=m;i++) 63 { 64 for(j=1;j<=n;j++) 65 { 66 a[i][j]+=b[i][j]; 67 68 } 69 } 70 71 int num=0; 72 73 74 75 for(i=1;i<=m;i++) 76 { 77 for(j=1;j<=n;j++) 78 { 79 if(a[i][j]) 80 break; 81 } 82 if(j>n) 83 num++; 84 85 } 86 87 88 for(i=1;i<=n;i++) 89 { 90 for(j=1;j<=m;j++) 91 { 92 if(a[j][i]) 93 break; 94 } 95 96 if(j>m) 97 num++; 98 } 99 100 101 102 printf("%d\n",num);103 }104 105 106 107 108 109 return 0;110 }

 

转载于:https://www.cnblogs.com/zjushuiping/archive/2012/05/30/2526723.html

你可能感兴趣的文章
Uart串口与RS232串口的区别
查看>>
【LeetCode】94. Binary Tree Inorder Traversal (3 solutions)
查看>>
(转)闪电效果的实现,中点位移法
查看>>
定义数组类型
查看>>
Java实现串口通信的小样例
查看>>
[转]一张图:你的车票是怎么被黄牛刷走的
查看>>
Firefox SVG getBBox方法返回'NS_ERROR_FAILURE'错误分析
查看>>
封装系统自带的Debug
查看>>
Grid_Oracle Grid Infrastructure概念介绍(概念)
查看>>
Netty系列之Netty百万级推送服务设计要点
查看>>
【百度地图API】北京周边7日游——图标按路线轨迹行动
查看>>
JAVA命令大全
查看>>
【百度地图API】让用户选择起点和终点的驾车导航
查看>>
揭秘淘宝286亿海量图片存储与处理架构
查看>>
得到工程的绝对路径
查看>>
iOS设置导航栏透明度
查看>>
怎样区分直连串口线和交叉串口线?
查看>>
【吐槽】火车票一票难求啊
查看>>
面向对象设计
查看>>
hdu1047 Integer Inquiry 多次大数相加
查看>>