九度oj-1001-Java
题目描述:
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的更多相关文章
- 九度oj 1001 A+B for Matrices 2011年浙江大学计算机及软件工程研究生机试真题
题目1001:A+B for Matrices 时间限制:1 秒 内存限制:32 兆 特殊判题:否 提交:15235 解决:6172 题目描述: This time, you are supposed ...
- 九度OJ 1001:A+B for Matrices
时间限制:1 秒 内存限制:32 兆 特殊判题:否 提交:17682 解决:7079 题目描述: This time, you are supposed to find A+B where A and ...
- 九度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. ...
- 九度OJ 题目1384:二维数组中的查找
/********************************* * 日期:2013-10-11 * 作者:SJF0115 * 题号: 九度OJ 题目1384:二维数组中的查找 * 来源:http ...
- hdu 1284 关于钱币兑换的一系列问题 九度oj 题目1408:吃豆机器人
钱币兑换问题 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Sub ...
- 九度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】题目1040:Prime Number 解题报告
[九度OJ]题目1040:Prime Number 解题报告 标签(空格分隔): 九度OJ 原题地址:http://ac.jobdu.com/problem.php?pid=1040 题目描述: Ou ...
- 【九度OJ】题目1163:素数 解题报告
[九度OJ]题目1163:素数 解题报告 标签(空格分隔): 九度OJ 原题地址:http://ac.jobdu.com/problem.php?pid=1163 题目描述: 输入一个整数n(2< ...
随机推荐
- nuxus 3在Maven项目的配置和POM文件的配置
在nuxus 3中的Maven默认会创建三个仓库,这三个仓库的关系如下: public是release和snapshot的全集,release默认为关闭状态,所以在配置nexus 3时需要将其开启. ...
- TCP编程的迷惑
server : ip -- 192.168.96.132 client: ip--192.168.96.131 在服务端,accept函数的其中一个入参是listen-socket,会返回一个新的c ...
- linux-socket connect阻塞和非阻塞模式 示例
~/cpp$ ./connect 192.168.1.234 1234 kkkk block mode: ubuntu 14.04 : time used:21.0.001053s connect ...
- CLR是如何被加载并工作的
当运行Windows应用程序的时候,CLR总是默默地为服务着.CLR到底是如何被加载并运行呢? 首先,Microsoft专门为CLR定义了一个标准的COM接口. 安装某个版本的.NET Framewo ...
- Windows Phone本地数据库(SQLCE):5、[Association]attribute(翻译)(转)
这是“windows phone mango本地数据库(sqlce)”系列短片文章的第五篇. 为了让你开始在Windows Phone Mango中使用数据库,这一系列短片文章将覆盖所有你需要知道的知 ...
- 使用断言NSAssert()调试程序错误
NSAssert()只是一个宏,用于开发阶段调试程序中的Bug,通过为NSAssert()传递条件表达式来断定是否属于Bug,满足条件返回真值,程序继续运行,如果返回假值,则抛出异常,并切可以自定义异 ...
- 教你调用数据库读取短信 记事本 通讯录文件,让ios5的短信恢复到ios4
由于高版本的ios固件向下恢复到低版固件时无法通过itunes恢复备份,所以一些数据,比如SMS需要通过提取文件的方式单独进行备份恢复特别是ios5的短信,之前很是头痛,直接将文件恢复到指定目录修改权 ...
- 【python】python安装步骤
1.官网下载python 官网地址:https://www.python.org/getit/ 2.下载完成后点击安装 勾选Add python to PATH 是可以自己去配置环境变量的 注意:这里 ...
- WordPress主题开发:截取标题或内容
截取可以用wp_trim_words() 用法: <?php $trimmed = wp_trim_words( $text, $num_words = 55, $more = null ); ...
- SQL:四舍五入和截取
四舍五入 , ) 截取 , )