题目描述:

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 -60

样例输出:

1

5

简单翻译一下

先输入矩阵行和列的数,再列出2个矩阵的数字,然后矩阵相加,算出行数都是零和列数都是零的总和。

Java

import java.util.ArrayList;
import java.util.List;
import java.util.Scanner; public class Main { public static void main(String[] args) {
List<Integer> mList = new ArrayList<Integer>();
Scanner cin = new Scanner(System.in);
int rows;
while ((rows = cin.nextInt()) != 0) {
int columns;
int totalTmp = 0;
int total = 0;
columns = cin.nextInt();
int[][] arrays1 = new int[rows][columns];
int[][] arrays2 = new int[rows][columns];
for (int i = 0; i < rows; i++) {
for (int j = 0; j < columns; j++) {
arrays1[i][j] = cin.nextInt();
}
}
for (int i = 0; i < rows; i++) {
for (int j = 0; j < columns; j++) {
arrays2[i][j] = cin.nextInt();
totalTmp = totalTmp | (arrays1[i][j] + arrays2[i][j]);
}
if (totalTmp == 0) {
total++;
}
totalTmp = 0;
} for (int colum = 0; colum < columns; colum++) {
for (int row = 0; row < rows; row++) {
totalTmp = totalTmp
| (arrays1[row][colum] + arrays2[row][colum]);
}
if (totalTmp == 0) {
total++;
}
totalTmp = 0;
}
mList.add(total);
}
for (int num : mList) {
System.out.println(num + "");
} }
}

我是天王盖地虎的分割线

九度oj-1001-Java的更多相关文章

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

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

  2. 九度OJ 1001:A+B for Matrices

    时间限制:1 秒 内存限制:32 兆 特殊判题:否 提交:17682 解决:7079 题目描述: This time, you are supposed to find A+B where A and ...

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

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

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

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

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

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

  6. hdu 1284 关于钱币兑换的一系列问题 九度oj 题目1408:吃豆机器人

    钱币兑换问题 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Sub ...

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

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

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

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

  9. 【九度OJ】题目1040:Prime Number 解题报告

    [九度OJ]题目1040:Prime Number 解题报告 标签(空格分隔): 九度OJ 原题地址:http://ac.jobdu.com/problem.php?pid=1040 题目描述: Ou ...

  10. 【九度OJ】题目1163:素数 解题报告

    [九度OJ]题目1163:素数 解题报告 标签(空格分隔): 九度OJ 原题地址:http://ac.jobdu.com/problem.php?pid=1163 题目描述: 输入一个整数n(2< ...

随机推荐

  1. haskell学习资料

    Haskell基础语法 Real World Haskell 中文版 Haskell趣学指南

  2. JS删除String里某个字符的方法

    关于JS删除String里的字符的方法,一般使用replace()方法.但是这个方法只会删除一次,如果需要将string里的所以字符都删除就要用到正则. 1 2 3 4 var str = " ...

  3. linux socket编程示例

    #include <sys/socket.h> #include <netinet/in.h> #include <arpa/inet.h> #include &l ...

  4. CRM上线之路 走上了CRM实施顾问-第12天上班 -第三周

    今天是周五,<CRM初期需求说明>是经理们商讨的,总共2张纸,根据两次会议,我写了<CRM需求说明>总共18面. 这是这周的工作汇报,其实,报告是我一天内写出来的,中午饭都没吃 ...

  5. mexHttpBinding协议 【发布元数据终结点】

    我们需要知道很多东西才能使用微软通信基础架构(WCF)来开发应用程序.尽管这本书已经试着囊括普通开发人员需要了解的WCF所有内容,也还是有一些内容没有讨论到.附录的主要目的是填充这些罅隙. 发布元数据 ...

  6. 在 DELPHI 中 procedure 型变量与 method 型变量的区别

    Procedure型变量: 在DELPHI中,函数.过程的地址可以赋给一个特殊类型的变量,变量可用如下方式声明: var p : procedure(num:integer); //过程 或: var ...

  7. [Winform]在关闭程序后,托盘不会消失的问题

    摘要 在开发winform程序时,添加了系统托盘,然发现在程序关闭后,托盘并不会消失,鼠标放在上面之后,才会消失.猜测是资源没有释放干净引起的.托盘作为form的组件,应该会随着form的关闭而释放啊 ...

  8. Android Service总结02 service介绍

    Android Service总结02 service介绍 版本 版本说明 发布时间 发布人 V1.0 介绍了Service的种类,常用API,生命周期等内容. 2013-03-16 Skywang ...

  9. could not load inserted library: /usr/lib/libgmalloc.dylib

    本人也刚开始学习iphone开发,最近维护一个程序时,不知道怎么弄的,不能build到真机了,到模拟器没有什么问题,出现的错误是 :---->>>could not load ins ...

  10. PPT幻灯片放映不显示备注,只让备注显示在自己屏幕上-投影机 设置

    无论是老师或是讲师还是即将要演讲的人,在讲课之前一定会做好课件,到哪一页该讲哪些内容,到哪里该如何去讲等等.那么一般的讲师会将这些课件存放到哪里呢?是用个书本记载下来呢,还是直接存放到电脑上呢?其实本 ...