ellesehc

Incorrect percolation

Oct 21st, 2015
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.63 KB | None | 0 0
  1.  
  2. package check;
  3.  
  4. public class Check
  5. {
  6.  
  7.     public static void main(String[] args)
  8.     {
  9.         String input = "1,0,0,0,0;0,1,0,0,0;0,1,0,0,0;0,0,1,0,0;0,0,0,0,0";
  10.         String[] input1 = input.split(";");
  11.         String[][] input2 = new String[input1.length][];
  12.        
  13.         int mark1 = 0;
  14.         int mark2 = 0;
  15.         int check = 1;
  16.        
  17.         for(int x = 0; x < input1.length; x++)
  18.         {
  19.             input2[x] = input1[x].split(",");
  20.         }
  21.        
  22.         if(input1.length == 1)
  23.         {
  24.             for(int x = 0; x < input1.length; x++)
  25.             {
  26.                 if(input1[x].equals("1"))
  27.                     check = 1;
  28.             }
  29.         }
  30.        
  31.         else
  32.         {
  33.             for(int y = 0; y<input1.length; y++)
  34.             {
  35.                 for(int x = 0; x < input2[y].length; x++)
  36.                 {
  37.                     if(input2[y][x].equals("1") && y == 0)
  38.                         mark1 = x;
  39.                    
  40.                     else if(input2[y][x].equals("1"))
  41.                         mark2 = x;
  42.                 }
  43.                
  44.                 if((mark2 -1 == mark1 || mark2 == mark1 || mark2 + 1 == mark1) && input1[y].contains("1") && check == 1)
  45.                     check = 1;
  46.                
  47.                 else
  48.                     check = 0;
  49.                
  50.                 if(y == 2)
  51.                 {
  52.                      mark1 = mark2;
  53.                 }
  54.                
  55.             }
  56.         }
  57.        
  58.         if(check == 1)
  59.             System.out.println("yes");
  60.        
  61.         else
  62.             System.out.println("no");
  63.     }
  64.    
  65. }
Advertisement
Add Comment
Please, Sign In to add comment