时间限制: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
来源:
2011年浙江大学计算机及软件工程研究生机试真题

思路:

本题的意思是计算两个矩阵的和中, 全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的更多相关文章

  1. 九度oj 1001 A+B for Matrices 2011年浙江大学计算机及软件工程研究生机试真题

    题目1001:A+B for Matrices 时间限制:1 秒 内存限制:32 兆 特殊判题:否 提交:15235 解决:6172 题目描述: This time, you are supposed ...

  2. 九度OJ 题目1384:二维数组中的查找

    /********************************* * 日期:2013-10-11 * 作者:SJF0115 * 题号: 九度OJ 题目1384:二维数组中的查找 * 来源:http ...

  3. 九度oj题目&amp;吉大考研11年机试题全解

    九度oj题目(吉大考研11年机试题全解) 吉大考研机试2011年题目: 题目一(jobdu1105:字符串的反码).    http://ac.jobdu.com/problem.php?pid=11 ...

  4. 【九度OJ】题目1069:查找学生信息 解题报告

    [九度OJ]题目1069:查找学生信息 解题报告 标签(空格分隔): 九度OJ [LeetCode] http://ac.jobdu.com/problem.php?pid=1069 题目描述: 输入 ...

  5. 【九度OJ】题目1174:查找第K小数 解题报告

    [九度OJ]题目1174:查找第K小数 解题报告 标签(空格分隔): 九度OJ 原题地址:http://ac.jobdu.com/problem.php?pid=1174 题目描述: 查找一个数组的第 ...

  6. 【九度OJ】题目1181:遍历链表 解题报告

    [九度OJ]题目1181:遍历链表 解题报告 标签(空格分隔): 九度OJ http://ac.jobdu.com/problem.php?pid=1181 题目描述: 建立一个升序链表并遍历输出. ...

  7. 九度oj 题目1087:约数的个数

    题目链接:http://ac.jobdu.com/problem.php?pid=1087 题目描述: 输入n个整数,依次输出每个数的约数的个数 输入: 输入的第一行为N,即数组的个数(N<=1 ...

  8. 九度OJ 1502 最大值最小化(JAVA)

    题目1502:最大值最小化(二分答案) 九度OJ Java import java.util.Scanner; public class Main { public static int max(in ...

  9. 九度OJ,题目1089:数字反转

    题目描述: 12翻一下是21,34翻一下是43,12+34是46,46翻一下是64,现在又任意两个正整数,问他们两个数反转的和是否等于两个数的和的反转. 输入: 第一行一个正整数表示测试数据的个数n. ...

随机推荐

  1. jar文件的Eclipse插件安装

    以[zigen.plugin.db_1.2.2.v20101009.jar]为例. (1)在[\eclipse\dropins]目录下新建一个目录,例如[myplugin] (2)上面新建的n目录下建 ...

  2. Transportation poj1040

    Ruratania is just entering capitalism and is establishing new enterprising activities in many fields ...

  3. es6 - filter for-chrome

    'use strict'; let numbers = [1, 2, 3, 4, 5, 6, 7, 8, 9]; // 除去取余2的 - es6 let es5OddNumbers = numbers ...

  4. ionic准备之angular基础——dom操作相关(6)

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  5. Google Chrome 35 Released – Install on RHEL/CentOS 6 and Fedora 20-15

    Google Chrome is a freeware web browser developed by Google Inc. Google Chrome team proudly announce ...

  6. foreach和volist的区别

      foreach和volist的区别   1.foreach标签foreach标签用于循环输出:foreach(name,item,key)name(必须):要输出的数据模板变量item(必须):循 ...

  7. delphi的基本数据类型

    2017年06月07日 11:02:25 阅读数:402 分类 范围 字节 备注 简单类型 序数 整数 Integer -2147483648 .. 2147483647 4 有符号32位 Cardi ...

  8. H5中滚动卡顿的问题

    加入-webkit-overflow-scrolling: touch;即可

  9. 【POJ 2400】 Supervisor, Supervisee(KM求最小权匹配)

    [POJ 2400] Supervisor, Supervisee(KM求最小权匹配) Supervisor, Supervisee Time Limit: 1000MS   Memory Limit ...

  10. Selection Problem (选择问题)

    在一个由n个元素组成的集合中,第i个“顺序统计量(order statistic)”是该集合中第i小的元素.例如,在一个由n个元素组成的集合中,最小值是第1个顺序统计量,最大值是第n个顺序统计量.而“ ...