9度oj 题目1001:A+B for Matrices【水题】

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

时间限制:1 秒

内存限制:32 兆

特殊判题:

提交:13653

解决:5575

题目描述:

    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年浙江大学计算机及软件工程研究生机试真题
题意:给出2个n*m的矩阵,然后相加,判断有多少行或者列的值均为0
import java.util.Scanner;
public class Main 
{
    public static void main(String[] args) 
    {
        Scanner cin = new Scanner(System.in);
        int [][]a = new int[20][20];
        int n,m;
        while(1>0)
        {
            n=cin.nextInt();
            if(n==0)return ;
            m=cin.nextInt();
            for (int i = 0; i<n; i++)
            {
                for (int j = 0; j < m; j++)
                {
                    a[i][j] = cin.nextInt();
                }
            }
            for (int i = 0; i<n; i++)
            {
                for (int j = 0; j < m; j++)
                {
                    int t = cin.nextInt();
                    a[i][j] +=t; 
                }
            }
            int count = 0;
            for(int i=0,j=0;i<n;i++)
            {
                for(j=0;j<m;j++)
                {
                    if(a[i][j]!=0)
                        break;
                }
                if(j==m) count++;
            }
            for(int i=0,j=0;i<m;i++)
            {
                for(j=0;j<n;j++)
                {
                    if(a[j][i]!=0)
                        break;
                }
                if(j==n) count++;
            }
            System.out.println(count);
        } 
    }  
}
目录
相关文章
|
测试技术 开发工具 Android开发
跨平台的视频采集、直播SDK SmarterStreaming
SmarterStreaming 跨平台的视频采集、直播SDK(支持Windows/android/iOS,支持私有协议和RTMP推流),也许是国内最靠谱的视频直播推流、播放SDK之一,助您轻松实现类似于花椒、映客、斗鱼手机直播推送与播放。
2116 0
|
JavaScript 前端开发 API
花了一天的时间,地板式扫盲了vue3中所有API盲点
这篇文章全面介绍了Vue3中的API,包括组合式API、选项式API等内容,旨在帮助开发者深入了解并掌握Vue3的各项功能。
花了一天的时间,地板式扫盲了vue3中所有API盲点
bigdecimal加减乘除
bigdecimal加减乘除
|
PyTorch 算法框架/工具
PyTorch中 nn.Conv2d与nn.ConvTranspose2d函数的用法
PyTorch中 nn.Conv2d与nn.ConvTranspose2d函数的用法
734 2
PyTorch中 nn.Conv2d与nn.ConvTranspose2d函数的用法
|
安全 Android开发 数据安全/隐私保护
制作系统签名
五月打卡
228 0
|
Java Maven Spring
Spring Boot中的自定义Starter开发
Spring Boot中的自定义Starter开发
|
SQL 关系型数据库 MySQL
关于MySQL8.0.16压缩包安装配置教程
关于MySQL8.0.16压缩包安装配置教程
|
存储 Java 容器
Java 中的 java.nio.FloatBuffer 类
Java 中的 java.nio.FloatBuffer 类
179 0
|
编译器 程序员 C++
[Eigen中文文档] C++中的template和typename关键字
在C++中,template和typename关键字有两种用途。其中一个在程序员中相当有知名度:用于定义模板。另一个用法则更为隐晦:用于指定一个表达式是引用模板函数还是类型。这经常困扰使用Eigen库的程序员,通常会导致编译器难以理解的错误信息,比如 expected expression 或 no match for operator<>。
378 0
|
程序员 C#
【C#】SignalR之主动推送信息的简单解决方案
在本篇文章中,将讲讲C#如何使用SignalR通讯 Core下的SignalR实现原理一样,只是写法不一样,主动推送消息的场景使用:页面登录后台管理系统,最新订单信息的通知等
491 0