Go to diff to previous submission
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; /* * To change this template, choose Tools | Templates and open the template in * the editor. */ /** * * @author cteam066 */ public class Grasshop { public static boolean inGrid(int[][] grid, int col, int row) { return (col >= 0 && col < grid[0].length && row >= 0 && row < grid.length); } public static int markNext(int[][] grid, int col, int row, int hops) { int count = 0; int[] dx = new int[]{1, 2, 2, 1, -1, -2, -2, -1}; int[] dy = new int[]{-2, -1, 1, 2, 2, 1, -1, -2}; for (int i = 0; i < 8; i++) { int col1 = col + dy[i]; int row1 = row + dx[i]; count++; grid[row1][col1] = hops; } } return count; } public static void print(int[][] grid) { for (int i = 0; i < grid.length; i++) { for (int j = 0; j < grid.length; j++) { if (grid[i][j] == -1) { } else { } else { } } } } } /** * @param args the command line arguments */ while (inputLine != null) { int[][] grid = new int[rows][cols]; grid[startR][startC] = -1; if(startR == endR && startC == endC) { inputLine = br.readLine(); continue; } int hops = 1; int marks = markNext(grid, startR, startC, hops); hops++; // print(grid); marks = 0; for (int i = 0; i < rows; i++) { for (int j = 0; j < cols; j++) { if (grid[i][j] == hops - 1) { marks += markNext(grid, i, j, hops); } } } hops++; } // print(grid); if (marks == 0) { } else { } inputLine = br.readLine(); } } }
--- c4.s970.cteam095.grasshop.java.0.Grasshop.java +++ c4.s989.cteam095.grasshop.java.0.Grasshop.java @@ -87,4 +87,12 @@ grid[endR][endC] = Integer.MAX_VALUE; + + if(startR == endR && startC == endC) { + + System.out.println(0); + inputLine = br.readLine(); + continue; + } + int hops = 1; int marks = markNext(grid, startR, startC, hops); @@ -108,5 +116,5 @@ } - //print(grid); + // print(grid); if (marks == 0) {