import java.io.*; import java.util.*; import java.text.*; import java.math.*; import java.util.regex.*; public class ShortPath { static void printShortestPath(int n, int i_start, int j_start, int i_end, int j_end) { // Print the distance along with the sequence of moves. int x1=0,y1=0,x2=n-1,y2=n-1; String UL,UR,R,LR,LL,L; //6 6 0 1 // X i = row,Y j= Col /* UL UR L R LL LR */ //UL L if(i_end < i_start && j_end < j_start){ //2nd Quad int rowDiff = Math.abs(i_end-i_start); int colDiff = Math.abs(j_end-j_start); if(rowDiff%2 != 0){ display(); return; }else{ colDiff = colDiff-(rowDiff/2); if(colDiff < 0){ display(); return; }else{ if(colDiff%2 !=0){ display(); return; } } } System.out.println((rowDiff/2) + (colDiff/2)); for(int i=0;i i_start && j_end > j_start){ //4th Quad int rowDiff = Math.abs(i_end-i_start); int colDiff = Math.abs(j_end-j_start); if(rowDiff%2 != 0){ display(); return; }else{ colDiff = colDiff-(rowDiff/2); if(colDiff < 0){ display(); return; }else{ if(colDiff%2 !=0){ display(); return; } } } System.out.println((rowDiff/2) + (colDiff/2)); for(int i=0;i j_start){ //1st Quad int rowDiff = Math.abs(i_end-i_start); int colDiff = Math.abs(j_end-j_start); if(rowDiff%2 != 0){ display(); return; }else{ colDiff = colDiff-(rowDiff/2); if(colDiff < 0){ display(); return; }else{ if(colDiff%2 !=0){ display(); return; } } } System.out.println((rowDiff/2) + (colDiff/2)); for(int i=0;i i_start && j_end < j_start){ //3st Quad int rowDiff = Math.abs(i_end-i_start); int colDiff = Math.abs(j_end-j_start); if(rowDiff%2 != 0){ display(); return; }else{ colDiff = colDiff-(rowDiff/2); if(colDiff < 0){ display(); return; }else{ if(colDiff%2 !=0){ display(); return; } } } System.out.println((rowDiff/2) + (colDiff/2)); for(int i=0;i