#include <iostream>
#include <string>
using namespace std;
int GetMin(int a, int b, int c)
{
return a > b? (b > c? c : b) : (a > c? c : a);
}
int MinDistance(string source, string target)
{
int m = source.length()+1;
int n = target.length()+1;
int dis[m][n];
for (int i = 0; i < m; ++i)
dis[i][0] = i;
for (int i = 0; i < n; ++i)
dis[0][i] = i;
for (int i = 1; i < m; ++i)
for (int j = 1; j < n; ++j)
dis[i][j] = GetMin(dis[i-1][j] +1, dis[i][j-1]+1
, dis[i-1][j-1]+(source[i-1] == target[j-1]?0:1));
return dis[source.length()] [target.length()];
}
int main(int argc, char** argv)
{
cout << MinDistance("abe" , "ace");
return 0;
}