使用编辑距离我必须找到两个字符串之间有多少编辑,我已经在下面的代码中完成了这些编辑,但是im卡住的部分正在打印输出假设要查看的2d数组像这样: 关于编辑距离的困惑
int editdistance(char *s, int ls, char *t, int lt)
{
int a, b, c;
if (!ls) return lt;
if (!lt) return ls;
if (s[ls] == t[ls])
return editdistance(s, ls - 1, t, lt - 1);
a = editdistance(s, ls - 1, t, lt - 1);
b = editdistance(s, ls, t, lt - 1);
c = editdistance(s, ls - 1, t, lt );
if (a > b) a = b;
if (a > c) a = c;
return a + 1;
}
int main()
{
char s1[100];
char s2[100];
printf("first: \n");
scanf("%s",s1);
printf("second: \n");
scanf("%s",s2);
printf("edit distance: %d\n", editdistance(s1, strlen(s1), s2, strlen(s2)));
return 0;
}
你看过http://stackoverflow.com/questions/40413578/edit-distance-matrix? –