Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Arrays;
- import java.util.Scanner;
- public class LabGround {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- String[] dimensions1 = scanner.nextLine().split("\\s+");
- int rows1 = Integer.parseInt(dimensions1[0]);
- int cols1 = Integer.parseInt(dimensions1[1]);
- int[][] firstM = new int[rows1][cols1];
- for(int row = 0; row<rows1;row++){
- int[] line = Arrays.stream(scanner.nextLine().split("\\s+"))
- .mapToInt(Integer::parseInt)
- .toArray();
- for (int col = 0; col < cols1; col++) {
- firstM[row][col] = line[col];
- }
- }
- String[] dimensions2 = scanner.nextLine().split("\\s+");
- int rows2 = Integer.parseInt(dimensions2[0]);
- int cols2 = Integer.parseInt(dimensions2[1]);
- int[][] secondM = new int[rows2][cols2];
- for(int row = 0; row<rows2;row++){
- int[] line = Arrays.stream(scanner.nextLine().split("\\s+"))
- .mapToInt(Integer::parseInt)
- .toArray();
- for (int col = 0; col < cols2; col++) {
- secondM[row][col] = line[col];
- }
- }
- boolean areEqual = compareM(firstM,secondM);
- if(areEqual){
- System.out.println("equal");
- }else{
- System.out.println("not equal");
- }
- }
- private static boolean compareM(int[][] firstM, int[][] secondM) {
- if(firstM.length!=secondM.length){
- return false;
- }
- for (int i = 0; i < firstM.length ; i++) {
- int[] firstArr = firstM[i];
- int[]secondArr = secondM[i];
- if(firstArr.length != secondArr.length){
- return false;
- }
- for (int j = 0; j < firstArr.length; j++) {
- int firstElement = firstArr[j];
- int secondElement= secondArr[j];
- if(firstElement!=secondElement){
- return false;
- }
- }
- }
- return true;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement