题解 | #矩阵相等判定#

矩阵相等判定

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

import java.io.*;

public class Main {
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String[] nm = br.readLine().split(" ");
        int n = Integer.parseInt(nm[0]);
        int m = Integer.parseInt(nm[1]);
        String[][] array1 = new String[n][m];
        String[][] array2 = new String[n][m];
        for (int i = 0; i < n * 2; i++) {
            String[] arr = br.readLine().split(" ");
            if (i < n) {
                for (int j = 0; j < m; j++) {
                    array1[i][j] = arr[j];
                }
            } else {
                for (int j = 0; j < m; j++) {
                    array2[i - n][j] = arr[j];
                }
            }
        }
        System.out.print(judge(array1, array2, n, m));
    }
    
    public static String judge(String[][] arr1, String[][] arr2, int row, int column) {
        for (int i = 0; i < row; i++) {
            for (int j = 0; j < column; j++) {
                if (!arr1[i][j].equals(arr2[i][j])) {
                    return "No";
                }
            }
        }
        return "Yes";
    }
}

全部评论

相关推荐

不愿透露姓名的神秘牛友
02-16 22:33
杉川机器人 嵌入式工程师 18.0k*13.0, 年终奖1~9个月浮动
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客企业服务