Advertisement
PepperoniPapaya

N M array

Dec 8th, 2015
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.38 KB | None | 0 0
  1. /*
  2.  * To change this license header, choose License Headers in Project Properties.
  3.  * To change this template file, choose Tools | Templates
  4.  * and open the template in the editor.
  5.  */
  6. package javaapplication5;
  7.  
  8. import java.io.BufferedReader;
  9. import java.io.IOException;
  10. import java.io.InputStreamReader;
  11. import java.util.ArrayList;
  12.  
  13. /**
  14.  *
  15.  * @author HoangLong
  16.  */
  17. public class JavaApplication5 {
  18.  
  19.     /**
  20.      * @param args the command line arguments
  21.      */
  22.     public static void main(String[] args) throws IOException {
  23.         // 自分の得意な言語で
  24.         // Let's チャレンジ!!
  25.         String line, line2;
  26.         int n, m;
  27.         int i, j;
  28.         ArrayList<ArrayList<Integer>> arrayN = new ArrayList<>();
  29.         ArrayList<ArrayList<Integer>> arrayM = new ArrayList<>();
  30.  
  31.         BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
  32.         line = br.readLine();
  33.         n = Integer.parseInt(line);
  34.         for (i = 0; i < n; i++) {
  35.             line = br.readLine();
  36.             line2 = line.replaceAll("\\s+", "");
  37.             arrayN.add(new ArrayList<>());
  38.             for (j = 0; j < n; j++) {
  39.                 arrayN.get(i).add(Character.getNumericValue(line2.charAt(j)));
  40.             }
  41.         }
  42.  
  43.         line = br.readLine();
  44.         m = Integer.parseInt(line);
  45.         for (i = 0; i < m; i++) {
  46.             line = br.readLine();
  47.             line2 = line.replaceAll("\\s+", "");
  48.             arrayM.add(new ArrayList<>());
  49.             for (j = 0; j < m; j++) {
  50.                 arrayM.get(i).add(Character.getNumericValue(line2.charAt(j)));
  51.             }
  52.         }
  53.  
  54.         int resultV = 0;
  55.         int resultH = 0;
  56.  
  57.         result_found:
  58.         for (resultV = 0; resultV <= n - m; resultV++) {
  59.             for (resultH = 0; resultH <= n - m; resultH++) {
  60.                 wrong_result:
  61.                 for (i = 0; i < m; i++) {
  62.                     for (j = 0; j < m; j++) {
  63.                         if (arrayN.get(resultV + i).get(resultH + j) != arrayM.get(i).get(j)) {
  64.                             break wrong_result;
  65.                         }
  66.                         if (i == m - 1 && j == m - 1) {
  67.                             break result_found;
  68.                         }
  69.                     }
  70.                 }
  71.  
  72.             }
  73.         }
  74.  
  75.         System.out.println(resultV + " " + resultH);
  76.  
  77.     }
  78.  
  79. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement