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[0].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, startC, startR, hops); // print(grid); hops++; 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, j, i, hops); } } } } //print(grid); if (marks == 0) { } else { } inputLine = br.readLine(); } } }
--- c4.s1048.cteam095.grasshop.java.0.Grasshop.java +++ c4.s1050.cteam095.grasshop.java.0.Grasshop.java @@ -96,5 +96,5 @@ int hops = 1; - int marks = markNext(grid, startR, startC, hops); + int marks = markNext(grid, startC, startR, hops); while (grid[endR][endC] == Integer.MAX_VALUE && marks > 0) {