//Anton Dubrau
//comp202, summer 2010, ass5 solutions

//StringUtils provides some useful methods


class StringUtils{

  //computes the edit distance of this string to a given other ComparableString
  public static int getDistance(String s, String t){
    int m = s.length();
    int n = t.length();

    int[][] d = new int[m+1][n+1];

    for (int i = 0; i <= m; i ++){
      d[i][0] = i;
    }
    
    for (int j = 0; j <= n; j ++){
      d[0][j] = j;
    }

    for (int j = 1; j <= n; j++){
      for (int i = 1; i <= m; i++){
        if (s.charAt(i-1) == t.charAt(j-1)){
          d[i][j] = d[i-1][j-1];
        } else {
          d[i][j] = min(d[i-1][j]  + 1,
                        d[i]  [j-1]+ 1,
                        d[i-1][j-1]+ 1);
        }
      }
    }

    return d[m][n];

  }

  //minimum of three numbers
  private static int min(int a, int b, int c){
    return Math.min(a,Math.min(b,c));
  }


  //filters out all characters from 1st argument, and keeps only the characters that 
  //are present in 2nd argument
  public static String filter(String text, String mask){
    String t = "";
    for (int i = 0; i < text.length(); i++){
      char c = text.charAt(i);
      if (mask.indexOf(c) >= 0){
        t += c;
      }
    }
    return t;
  }
  
  //test code - main simply takes edit distance of two command line arguments
  public static void main(String[] args){
    System.out.println(getDistance(args[0],args[1]));
  }

}


