cpp的实现方法,cpp有点那啥,算了。 = =
记得#include别丢了。。。
public: Double __gc* Levenshtein_Distance(String __gc* str1, String __gc* str2)
{
Int64 __gc* d = 0;
if (str1->Length > str2->Length)
{
d = str1->Length;
}
else
{
d = str2->Length;
}
return (1 - (*static_cast<__box Double*>(this->LD(str1, str2)) / *static_cast<__box Double*>(d)));
}
public: Int32 __gc* LD(String __gc* s, String __gc* t)
{
Int32 __gc* i;
Int32 __gc* n = Strings:[s:10]en(s);
Int32 __gc* m = Strings:[s:10]en(t);
if (n == 0)
{
return m;
}
if (m == 0)
{
return n;
}
Int32 __gc* dis __gc [,] = __gc new Int32 __gc*[(n + 1), (m + 1)];
Int32 __gc* R$t_i4$L0 = n;
for (i = 0; (i <= R$t_i4$L0); i++)
{
dis[i, 0] = i;
}
Int32 __gc* R$t_i4$L1 = m;
Int32 __gc* j = 0;
while ((j <= R$t_i4$L1))
{
dis[0, j] = j;
j++;
}
Int32 __gc* R$t_i4$L2 = n;
for (i = 1; (i <= R$t_i4$L2); i++)
{
String __gc* s_i = Strings::Mid(s, i, 1);
Int32 __gc* R$t_i4$L3 = m;
for (j = 1; (j <= R$t_i4$L3); j++)
{
Int32 __gc* cost;
String __gc* t_j = Strings::Mid(t, j, 1);
if (s_i == t_j)
{
cost = 0;
}
else
{
cost = 1;
}
dis[i, j] = this->Minimum((dis[(i - 1), j] + 1), (dis[i, (j - 1)] + 1), (dis[(i - 1), (j - 1)] + cost));
}
}
Int32 __gc* LD = dis[n, m];
dis = 0;
return LD;
}
private: Int32 __gc* Minimum(Int32 __gc* a, Int32 __gc* b, Int32 __gc* c)
{
Int32 __gc* min = a;
if (b < min)
{
min = b;
}
if (c < min)
{
min = c;
}
return min;
}