使用编辑距离我必须找到两个字符串之间有多少编辑,我已经在下面的代码中完成了,但我坚持的部分是打印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;
}