import java.io.*; import java.util.*; import java.lang.*; import java.*; class PathFinder { public static void main(String args[]) { try{ // Open the file FileInputStream fstream = new FileInputStream(args[0]); // Get the object of DataInputStream DataInputStream in = new DataInputStream(fstream); BufferedReader br = new BufferedReader(new InputStreamReader(in)); String strLine; String strLine2; //Read first line strLine = br.readLine(); strLine2=strLine; in.close(); BufferedWriter out2 = new BufferedWriter(new FileWriter("c"+args[0])); strLine2 = "["+strLine2.substring(0,strLine2.length()-1)+"]"; out2.write(strLine2); out2.close(); int len = strLine.length(); int dim = len/3; int i=0; int[] inX = new int[dim]; int[] inY = new int[dim]; int x1; int y1; int x2; int y2; //parse the string while(i< len) { inX[i/3] = Integer.parseInt(""+strLine.charAt(i)); inY[i/3] = Integer.parseInt(""+strLine.charAt(i+1)); i=i+3; } //Output string start String strOut = "["+inX[0]+inY[0]+","; for(i=0; i < dim-1; i++) { x1 = inX[i]; y1 = inY[i]; x2 = inX[i+1]; y2 = inY[i+1]; if (x1 >= x2) while (x1 != x2) { x1--; strOut = strOut + x1; strOut = strOut + y1; strOut = strOut + ","; } else while (x1 != x2) { x1++; strOut = strOut + x1; strOut = strOut + y1; strOut = strOut + ","; } if (y1 >= y2) while (y1 != y2) { y1--; strOut = strOut + x1; strOut = strOut + y1; strOut = strOut + ","; } else while (y1 != y2) { y1++; strOut = strOut + x1; strOut = strOut + y1; strOut = strOut + ","; } } //string end strOut = strOut.substring(0,strOut.length()-1)+"]"; //write the updated path BufferedWriter out = new BufferedWriter(new FileWriter(args[0])); out.write(strOut); out.close(); }catch (Exception e){//Catch exception if any System.err.println("Error: " + e.getMessage()); } } }