博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
九度OJ-1001-A+B矩阵-有些小技巧
阅读量:5230 次
发布时间:2019-06-14

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

题目1001:A+B for Matrices

时间限制:1 秒

内存限制:32 兆

特殊判题:

提交:22974

解决:9099

题目描述:

    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
来源:

 

 

 

 

 

#include 
int ma[11][11];int mb[11][11];int main() { int a, b; while(scanf("%d", &a)) { if(a == 0) return 0; scanf("%d", &b); for(int i = 0; i < a; i++) { for(int j = 0; j < b; j++) { scanf("%d", &ma[i][j]); } } for(int i = 0; i < a; i++) { for(int j = 0; j < b; j++) { scanf("%d", &mb[i][j]); mb[i][j] += ma[i][j]; } } // sum int su = 0; int co = 0; for(int i = 0; i < a; i++) { for(int j = 0; j < b; j++) { if(mb[i][j] != 0){ co++; // printf("%d %d\n", i, j); break; } } if(co == 0) { su++; // printf("%d %d\n", i, su); } else co = 0; } co = 0; for(int j = 0; j < b; j++) { for(int i = 0; i < a; i++) { if(mb[i][j] != 0) { co++; break; } } if(co == 0) { su++; } else co = 0; } printf("%d\n", su); } return 0;}

 

转载于:https://www.cnblogs.com/QingHuan/p/7100314.html

你可能感兴趣的文章
C#调用ADOX创建ACCESS数据文件后关闭连接
查看>>
VUE常见的语法
查看>>
navicat premium各个版本及激活
查看>>
Array.Sort 谷歌内核 数组大小超过10 排序字段都一致 返回的数组非原数组
查看>>
实例六分页处理
查看>>
转载 失踪
查看>>
P1113 杂务
查看>>
RQNOJ:PID30 / [stupid]愚蠢的矿工☆(树形背包)
查看>>
Sharepoint学习笔记—习题系列--70-576习题解析 -(Q141-Q143)
查看>>
Effective C++ 37绝不重新定义继承而来的缺省参数值
查看>>
翻译 - 【Dojo Tutorials】Fundamentals 1 Classy JavaScript with dojo/_base/declare
查看>>
EasyDarwin做转发延时太大?
查看>>
浅谈ldap以及jndi
查看>>
Python – locals和globals
查看>>
angular 1.6路由
查看>>
[原创]java WEB学习笔记28: 会话与状态管理Cookie 机制
查看>>
Session的生命周期之关于浏览器关闭后的Session
查看>>
git获取远程服务器的指定分支
查看>>
数组排序(选择排序和冒泡排序)
查看>>
WPF DelegateCommand 出现Specified cast is not valid
查看>>