九度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. ...
随机推荐
- 2017年开发者生态报告:Python最多人想尝试的编程语言(转载)
在过去的十年里,Python 语言获得了最大的增长幅度,已经成为最受欢迎的程序设计语言之一.JetBrains 近日发布了 2017 开发者生态报告,该报告包含开发人员对 11 种编程语言以及数据库和 ...
- Hadoop之Flume详解
1.日志采集框架Flume 1.1 Flume介绍 Flume是一个分布式.可靠.和高可用的海量日志采集.聚合和传输的系统. Flume可以采集文件,socket数据包等各种形式源数据,又可以将采集到 ...
- [转载]linux 清除系统cached
FROM: http://cqfish.blog.51cto.com/622299/197230 linux 清除系统cached top查看系统内存使用情况 Mem: 16432180k ...
- vue-router push
//push 方法一 对象 // this.$router.push({path:'HelloWorld2'}); //push 方法二 命名的路由 // this.$router.push({nam ...
- 01-2制作U盘启动盘--装机助理工具
在可以上网的电脑上执行制作启动盘的操作: 打开浏览器输入:http://www.zhuangjizhuli.com/upan.html 1.制作U盘启动盘: 2.下载 装机助理 软件 3.步骤: 第一 ...
- 【HttpClient4.5中文教程】【第一章 :基础】1.1运行请求(二)
很多其它HttpClient4.5中文教程请查看:点击打开链接 ==================================================================== ...
- CoreAnimation的使用小结
參考:http://www.cnblogs.com/wendingding/p/3801157.htmlhttp://www.cnblogs.com/wendingding/p/3802830.htm ...
- zoj 3827 Information Entropy 【水题】
Information Entropy Time Limit: 2 Seconds Memory Limit: 65536 KB Special Judge Information ...
- 什么是CouchDB?
※本文对CouchDB的解释是来自Apache CouchDB的官网的译文,如果有什么问题,请指正. 1.CouchDB简介 CouchDB是一种利用JSON文件,javascript作为MapRed ...
- Redis用LPUSH和RPOP实现消息队列
using System; using System.Collections.Generic; using System.Linq; using System.Text; using ServiceS ...