九度OJ 1001:A+B for Matrices
时间限制:1 秒
内存限制:32 兆
特殊判题:否
提交:17682
解决:7079
- 题目描述:
-
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
思路:
本题的意思是计算两个矩阵的和中, 全0行和全0列的个数。
代码:
#include <stdio.h> #define N 10 int main(void)
{
int m, n, i, j;
int a[N][N], b[N][N]; while (scanf("%d", &m) != EOF)
{
if (m == 0)
break; scanf("%d", &n);
for(i=0; i<m; i++)
{
for(j=0; j<n; j++)
{
scanf("%d", &a[i][j]);
}
}
int count = 0;
for(i=0; i<m; i++)
{
int zerorow = 1;
for(j=0; j<n; j++)
{
scanf("%d", &b[i][j]);
a[i][j] += b[i][j];
if (a[i][j] != 0)
zerorow = 0;
}
count += zerorow;
}
for(j=0; j<n; j++)
{
int zerocol = 1;
for(i=0; i<m; i++)
{
if (a[i][j] != 0)
zerocol = 0;
}
count += zerocol;
} printf("%d\n", count);
} return 0;
}
/**************************************************************
Problem: 1001
User: liangrx06
Language: C
Result: Accepted
Time:0 ms
Memory:912 kb
****************************************************************/
九度OJ 1001:A+B for Matrices的更多相关文章
- 九度oj 1001 A+B for Matrices 2011年浙江大学计算机及软件工程研究生机试真题
题目1001:A+B for Matrices 时间限制:1 秒 内存限制:32 兆 特殊判题:否 提交:15235 解决:6172 题目描述: This time, you are supposed ...
- 九度OJ 题目1384:二维数组中的查找
/********************************* * 日期:2013-10-11 * 作者:SJF0115 * 题号: 九度OJ 题目1384:二维数组中的查找 * 来源:http ...
- 九度oj题目&吉大考研11年机试题全解
九度oj题目(吉大考研11年机试题全解) 吉大考研机试2011年题目: 题目一(jobdu1105:字符串的反码). http://ac.jobdu.com/problem.php?pid=11 ...
- 【九度OJ】题目1069:查找学生信息 解题报告
[九度OJ]题目1069:查找学生信息 解题报告 标签(空格分隔): 九度OJ [LeetCode] http://ac.jobdu.com/problem.php?pid=1069 题目描述: 输入 ...
- 【九度OJ】题目1174:查找第K小数 解题报告
[九度OJ]题目1174:查找第K小数 解题报告 标签(空格分隔): 九度OJ 原题地址:http://ac.jobdu.com/problem.php?pid=1174 题目描述: 查找一个数组的第 ...
- 【九度OJ】题目1181:遍历链表 解题报告
[九度OJ]题目1181:遍历链表 解题报告 标签(空格分隔): 九度OJ http://ac.jobdu.com/problem.php?pid=1181 题目描述: 建立一个升序链表并遍历输出. ...
- 九度oj 题目1087:约数的个数
题目链接:http://ac.jobdu.com/problem.php?pid=1087 题目描述: 输入n个整数,依次输出每个数的约数的个数 输入: 输入的第一行为N,即数组的个数(N<=1 ...
- 九度OJ 1502 最大值最小化(JAVA)
题目1502:最大值最小化(二分答案) 九度OJ Java import java.util.Scanner; public class Main { public static int max(in ...
- 九度OJ,题目1089:数字反转
题目描述: 12翻一下是21,34翻一下是43,12+34是46,46翻一下是64,现在又任意两个正整数,问他们两个数反转的和是否等于两个数的和的反转. 输入: 第一行一个正整数表示测试数据的个数n. ...
随机推荐
- 项目笔记:导出Excel功能分sheet页插入数据
导出Excel功能分sheet页处理数据: /*导出EXCEL*/ public void createExcel() { log.info("导出Excel功能已经启动-BEGIN&quo ...
- ElasticSearch 相关性
1.相关性 ElasticSearch检索结果是按照相关性倒序排列的,相关性是什么,相关性又是如何计算的?每个文档都有相关性评分,用一个正浮点数字段 _score 来表示 . _score 的评分越高 ...
- Jquery.data()的值存放再什么地方的问题?
Where is jQuery.data() stored? Where does jQuery store the values of the data() that it sets to DOM ...
- 2017.4.18 putty和fileZilla的使用
putty:用来连接环境. fileZila:用来传递文件. (1)连接环境 centOS 7 点击putty.exe,输入地址.用户名.密码进行连接.端口输入22.用账号和密码登录. 进入到目录下, ...
- SharePoint 2013 表单认证使用ASP.Net配置工具加入用户
前 言 上面一篇博客,我们了解到怎样为SharePoint 2013配置表单身份认证.可是加入用户是一个麻烦事儿:事实上,我们还能够用Asp.Net的配置工具,为SharePoint 2013加入表单 ...
- android-SQLite数据库MVC关联实例源码(三层架构)
前两天布置下了一个期末练习,其中的重点是两个表之间的SQLite关联操作. 拿到题目,首先需要建库和关联表,下面是代码. 我使用简单的表插入,将数据的提交卸载onCreate方法中,这样不会发生写在主 ...
- 为什么我获取不到这个css样式?js原生获取css样式总结
还是自己遇到的一个坑的总结吧!与其说是坑不如说自己学艺不精,让我先哭一会!! 需求 简单就是获取一个css的height (好吧 就是一个这么简单的需求) 实践 好吧 长时间的JQ 我已经对原生无能了 ...
- java Map根据value排序
通用方法 public class MapUtil { public static <K, V extends Comparable<? super V>> Map<K, ...
- web前端性能优化汇总
一.概述 web前端性能优化主要点为:减少HTTP请求,减小请求文件大小.其他优化. 二.优化细节 1.减少HTTP请求 (1)使用缓存 (2)雪碧图 (3)合并文件 (4)将javascript和c ...
- 【Lucene】Apache Lucene全文检索引擎架构之构建索引2
上一篇博文中已经对全文检索有了一定的了解,这篇文章主要来总结一下全文检索的第一步:构建索引.其实上一篇博文中的示例程序已经对构建索引写了一段程序了,而且那个程序还是挺完善的.不过从知识点的完整性来考虑 ...