Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/c/71.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C 对编辑距离感到困惑吗_C_Algorithm_Edit Distance - Fatal编程技术网

C 对编辑距离感到困惑吗

C 对编辑距离感到困惑吗,c,algorithm,edit-distance,C,Algorithm,Edit Distance,使用编辑距离,我必须找到两个字符串之间的编辑次数,我在下面的代码中已经做过,但是我所坚持的部分是打印2d数组,输出应该是这样的: 如果我是对的,你正在寻找。这是中的一个算法。您看过了吗?那么问题是什么?翻译成C?(因为维基百科中有代码,你可以简单地复制) int editdistance(char *s, int ls, char *t, int lt) { int a, b, c; if (!ls) return lt; if (!lt) return ls;

使用编辑距离,我必须找到两个字符串之间的编辑次数,我在下面的代码中已经做过,但是我所坚持的部分是打印2d数组,输出应该是这样的:


如果我是对的,你正在寻找。这是中的一个算法。

您看过了吗?那么问题是什么?翻译成C?(因为维基百科中有代码,你可以简单地复制)
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;
}