Lab8-Puzzle15


5530155421  นายณัฐนัย โล้พิรุณ (COM22023) (2/13/2013 (2:27:49 PM))

MiniQuiz + TestScript
JLab>java Selftest 

JLab> testPuzzle15 : ok ok ok ok ok ok ok ok ok ok  (10.0/10.0)
JLab> : -----------------------------
JLab> : ?????? 10.0 ????? (???? 10.0)
JLab> : -----------------------------
JLab> :<POINT>10.0</POINT> (<TOTAL>10.0</TOTAL> )
JLab>

ได้ 10 คะแนน
Source Code
public class FifteenPuzzle {
  //---------------------------------------------------
  public static boolean solvable15Puzzle(int[][] b) {
  
  int c[] = new int[15]; int k = 0; int l1 =0; int b1 =0; 
  
  for (int i = 0; i < b.length; i++) {
    for (int j = 0; j < b[i].length; j++) {

      if (b[i][j] != 0) {
      c[k] = b[i][j];
      k++;
      }
    }
  }
  
  for (int i = 0; i < c.length ; i++) {
    for (int j = 0; j < c.length; j++) {
      if (i < j) {
         if (c[i] > c[j]) l1++;
       }
     
    }
  }
  
  for (int i = 0; i < b.length; i++) {
    for (int j = 0; j < b[i].length; j++) {
      if(b[i][j]==0) b1=i+1;
    }
  }
  if ((l1+b1) % 2 == 0) return true;
  else return false;



      
  }
  //---------------------------------------------------
  public static void main(String[] a) {
    int[][] ok = { { 1, 2, 3, 4 },
                    { 5, 6, 7, 8 },
                    { 9, 10, 12, 15 },
                    { 13, 14, 11, 0 } };
    int[][] nok = { { 1, 2, 3, 4 },
                    { 5, 6, 7, 8 },
                    { 9, 10, 11, 12 },
                    { 13, 15, 14, 0 } };
    System.out.println(solvable15Puzzle(ok));
    System.out.println(solvable15Puzzle(nok));

  }
}

SM=0, CM=30, ST=27, KY=684, TR=60:00
ERR = 60:00 ;
ERR = 60:00 ;
ERR = 60:00 ;
ERR = 60:00 ;
ERR = 60:00 ;
ERR = 60:00 ;
ERR = 60:00 ;
ERR = 60:00 ;
ERR = 60:00 ;
ERR = 60:00 ;
ERR = 60:00 ;
ERR = 60:00 ;
ERR = 60:00 ;
ERR = 60:00 ;
ERR = 60:00 ;
ERR = 60:00 ;
ERR = 60:00 ;
ERR = 60:00 ;
ERR = 60:00 ;
ERR = 60:00 ;
ERR = 60:00 ;
ERR = 60:00 ;
ERR = 60:00 ;
ERR = 60:00 ;
ERR = 60:00 ;
ERR = 60:00 ;
ERR = 60:00 ;
ERR = 60:00 ;
ERR = 60:00 ;
ERR = 60:00 ;