Go to diff to previous submission
/* * To change this template, choose Tools | Templates * and open the template in the editor. */ package folded; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; /** * * @author cteam028 */ public class Main { /** * @param args the command line arguments */ try { Main fm = new Main(); fm.init(); //Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex); } } String line; while((line = br.readLine()) != null) { // String a[] = line.split(" "); final int[] arr = new int[4]; parseIntArr(line.toCharArray(), arr); final int Ar = arr[0]; final int Ac = arr[1]; final int Tr = arr[2]; final int Tc = arr[3]; // int Ar = Integer.parseInt(a[0]); // int Ac = Integer.parseInt(a[1]); // int Tr = Integer.parseInt(a[2]); // int Tc = Integer.parseInt(a[3]); int pole[][][][] = new int[Tr][Tc][(Ar/Tr) + 2][(Ac/Tc) + 2]; for(int x=0; x < Ar; x++) { line = br.readLine(); char[] text = line.toCharArray(); for(int y=0; y < Ac; y++) { boolean inMap = (text[y] == 'X'); if(inMap){ for (int dx = 0; dx < Tr; dx++) { for (int dy = 0; dy < Tc; dy++) { pole[dx][dy][(x + dx)/Tr][(y + dy)/Tc] = 1; } } } } } for (int dx = 0; dx < Tr; dx++) { for (int dy = 0; dy < Tc; dy++) { int pocet = 0; for (int idxx = 0; idxx < (Ar/Tr) + 2; idxx++) { for (int idxy = 0; idxy < (Ac/Tc) + 2; idxy++) { if(pole[dx][dy][idxx][idxy] == 1) pocet++; } } } } } } public static void parseIntArr(char[] arr, int[] target) { int i = 0; int acc = -1; for(char ch :arr) { if(ch == ' ') { if(acc!= -1) { target[i++] = acc; acc = -1; } } else if(acc == -1) acc = ch - '0'; else acc = acc * 10 + (ch - '0'); } if(acc != -1) target[i] = acc; } }
--- c5.s576.cteam028.fm.java.0.Main.java +++ c5.s606.cteam028.fm.java.0.Main.java @@ -19,9 +19,9 @@ * @param args the command line arguments */ - public static void main(String[] args) { + public static void main(String[] args) throws Exception { try { Main fm = new Main(); fm.init(); - } catch (Exception ex) { + } catch (ArrayIndexOutOfBoundsException ex) { //Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex); } @@ -48,5 +48,5 @@ // int Tc = Integer.parseInt(a[3]); - int pole[][][][] = new int[Ar][Ac][(Ar/Tr) + 2][(Ac/Tc) + 2]; + int pole[][][][] = new int[Tr][Tc][(Ar/Tr) + 2][(Ac/Tc) + 2]; for(int x=0; x < Ar; x++) {