题解 | #矩阵相等判定#

矩阵相等判定

https://www.nowcoder.com/practice/2f058b1e89ae43f7ab650c0fd0b71fa8

import java.util.Scanner;

// 注意类名必须为 Main, 不要有任何 package xxx 信息
public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        // 注意 hasNext 和 hasNextLine 的区别
        int n = in.nextInt();
        int m = in.nextInt();
        int[][]arr1 = new int[n][m];
        int[][]arr2 = new int[n][m];
        int count=0;
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < m; j++) {
                arr1[i][j] = in.nextInt();
            }
        }
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < m; j++) {
                arr2[i][j] = in.nextInt();
            }
        }
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < m; j++) {
                if(arr1[i][j]==arr2[i][j]){
                    count++;
                }
            }
        }
        if(count==(n*m)){
            System.out.println("Yes");
        }else System.out.println("No");
    }
}

全部评论

相关推荐

昨天 15:23
门头沟学院 Java
难道你们背八股都不觉得累?现在每天背八股背的我想吐
想去大厂的土豆子:累不累都是对比出来的,八股可比高考、考研轻松多了
点赞 评论 收藏
分享
牛客383479252号:9,2学生暑期实习失利开始投小厂,给这群人整自信了
点赞 评论 收藏
分享
05-23 19:02
吉林大学 Java
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务