Advertisement
Guest User

Untitled

a guest
Dec 8th, 2016
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.25 KB | None | 0 0
  1. public void search_path(String [][] b, int [][] c, String s1, String s2){ //доделать
  2.        
  3.         int m = s1.length();
  4.         int n = s2.length();
  5.         int [][] c1 = new int[s1.length()+1][s2.length()+1];
  6.        
  7.         for (int i = 1; i <= m ; i++) c1[i][0] = i * c_d;
  8.         for (int j = 0; j <= n ; j++) c1[0][j] = j * c_i;
  9.        
  10.    
  11.         for (int i = 1; i <= m ; i++)
  12.             for (int j = 1; j <= n ; j++)
  13.             {
  14.                 if (s1.charAt(i-1) == s2.charAt(j-1)){
  15.                     //c1[i][j] = c1[i-1][j-1];
  16.                     b[i][j] = "diag/NOTHING";
  17.                 }
  18.                 else{
  19.                     int MIN = Math.min((c1[i][j-1]+c_i), //Insert
  20.                             Math.min((c1[i-1][j]+c_d), // Remove
  21.                             (c1[i-1][j-1]+c_r))); //Replace
  22.                     if (MIN == c1[i][j-1]+c_i){
  23.                         //c1[i][j] = c1[i][j-1];
  24.                         b[i][j] = "up/delete "+(j-1);
  25.                     }
  26.                     if (MIN == c1[i-1][j]+c_d){
  27.                         //c1[i][j] = c1[i-1][j];
  28.                         b[i][j] = "left/insert "+s2.charAt(j-1);
  29.                     }
  30.                     if (MIN == c1[i-1][j-1]+c_r){
  31.                         //c1[i][j] = c1[i-1][j-1];
  32.                         b[i][j] = "diag/replace "+i+" with "+s2.charAt(j-1);
  33.                     }
  34.                 }
  35.             }
  36.        
  37.        
  38.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement