Source code for submission s796

Go to diff to previous submission

Grasshop.java

  1.  
  2. import java.util.Scanner;
  3.  
  4. public class Grasshop {
  5.  
  6. public static void main(String[] args) {
  7. int i,z,j,k,i1,i2,j1,j2;
  8. boolean skok = false;
  9. int tah[][] = new int[9][2];
  10. tah[8][0]=1; tah[8][1]=2;
  11. tah[1][0]=2; tah[1][1]=1;
  12. tah[2][0]=2; tah[2][1]=-1;
  13. tah[3][0]=1; tah[3][1]=-2;
  14. tah[4][0]=-1; tah[4][1]=-2;
  15. tah[5][0]=-2; tah[5][1]=-1;
  16. tah[6][0]=-2; tah[6][1]=1;
  17. tah[7][0]=-1; tah[7][1]=2;
  18.  
  19. Scanner sc = new Scanner(System.in);
  20. while(sc.hasNext()){
  21. int r = sc.nextInt();
  22. int c = sc.nextInt();
  23. int gr = sc.nextInt();
  24. int gc = sc.nextInt();
  25. int lr = sc.nextInt();
  26. int lc = sc.nextInt();
  27.  
  28. int sach[][]= new int[c+1][r+1];
  29.  
  30. for(i=1;i<=c;i++){
  31. for(j=1;j<=r;j++){
  32. sach[i][j]=-1;
  33. }
  34. }
  35.  
  36. sach[gc][gr]=0;
  37. int krok=1;
  38. while(sach[lc][lr]==-1){
  39. skok = false;
  40. for(i1=1;i1<=c;i1++){
  41. for(i2=1;i2<=r;i2++){
  42. if(sach[i1][i2]==krok-1){
  43.  
  44. for(k=1;k<=8;k++){
  45. j1=i1+tah[k][0];
  46. j2=i2+tah[k][1];
  47.  
  48.  
  49. if((j2>0)&&(j2<r+1)&&(j1>0)&&(j1<c+1)){
  50. if(sach[j1][j2]==-1){
  51. sach[j1][j2]=krok;
  52. skok = true;
  53. }
  54. }
  55.  
  56. }
  57. }
  58. }
  59. }
  60. krok++;
  61. if(!skok){break;}
  62. }
  63. if(skok==true){System.out.println(sach[lr][lc]);}
  64. else {
  65. System.out.println("impossible");
  66. }
  67. }
  68.  
  69.  
  70. }
  71.  
  72. }
  73.  

Diff to submission s781

Grasshop.java

--- c4.s781.cteam060.grasshop.java.0.Grasshop.java
+++ c4.s796.cteam060.grasshop.java.0.Grasshop.java
@@ -1,13 +2,6 @@
 import java.util.Scanner;
 
-/**
- *
- * @author cteam060
- */
 public class Grasshop {
 
-    /**
-     * @param args the command line arguments
-     */
     public static void main(String[] args) {
       int i,z,j,k,i1,i2,j1,j2;
@@ -23,6 +17,4 @@
       tah[7][0]=-1; tah[7][1]=2;
       
-      
-      
       Scanner sc = new Scanner(System.in);
       while(sc.hasNext()){
@@ -44,5 +36,5 @@
         sach[gc][gr]=0;
         int krok=1;
-        while(sach[lr][lc]==-1){
+        while(sach[lc][lr]==-1){
           skok = false;  
           for(i1=1;i1<=c;i1++){