九度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. ...
随机推荐
- [转载]CentOS 6.5 安装五笔输入法
FROM:http://blog.sina.com.cn/s/blog_49d6d41c0101i0zs.html 1.一般安装了中文环境会默认安装了好多输入法,先删除了ibus sudo yum ...
- 配置Linux系统实现dhcp功能
配置Linux系统实现dhcp功能 1.背景及原理 DHCP(Dynamic Host Configuration Protocol,动态主机配置协议)通常被应用在大型的局域网络环境中,主要作用 ...
- Win7下nginx默认80端口被System占用,造成nginx启动报错的解决方案
Win7下nginx默认80端口被System占用,造成nginx启动报错的解决方案 在win7 32位旗舰版下,启动1.0.8版本nginx,显示如下错误: [plain] 2012/04/0 ...
- NYOJ82 迷宫寻宝(一)【BFS】
迷宫寻宝(一) 时间限制:1000 ms | 内存限制:65535 KB 难度:4 描写叙述 一个叫ACM的寻宝者找到了一个藏宝图.它依据藏宝图找到了一个迷宫,这是一个非常特别的迷宫,迷宫里有N个 ...
- 怎么运行Typescript
依据官方示例: npm i -g typescript 示例:tsc *.ts 实例:tsc hello.ts 不过以上实现的太有限制了,如下实现可满足正常测试以及学习使用 package,json ...
- 浏览器网页推断手机是否安装IOS/Androidclient程序
IOS 原理例如以下: 为HTML页面中的超链接点击事件添加一个setTimeout方法. 假设在iPhone上面500ms内,本机有应用程序能解析这个协议并打开程序,则这个回调方法失效. 假设本机没 ...
- Win8.1应用开发之Bing Maps
这里介绍怎样进行Bing Maps的开发.首先我们须要在我们的程序中引入Bing Map的SDK.详细方法,这里推荐一个链接<win8>使用Bing地图.这样一个hello world便出 ...
- C语言结构体及函数传递数组參数演示样例
注:makeSphere()函数返回Sphere结构体,main函数中.调用makeSphere()函数,传递的第一个參数为数组,传递的数组作为指针.
- dr-helper项目设计介绍(一个包括移动端和Web端的点餐管理系统)
一.源代码路径 https://github.com/weiganyi/dr-helper 二.界面 通过浏览器訪问Web服务,能够看到界面例如以下: ADT-Bundle编译project生成dr- ...
- Java中的split函数的用法
Java中的 split 函数是用于按指定字符(串)或正则去分割某个字符串,结果以字符串数组形式返回: 例如: String str="1234@abc"; String[] a ...