#include<stdio.h>
int dis(char *s1, int begin1, int end1, char *s2, int begin2, int end2)
{
if(begin1>end1)
{
if(begin2>end2)
{
return 0;
}
else
{
return end2-begin2+1;
}
}
if(begin2>end2)
{
if(begin1>end1)
{
return 0;
}
else
{
return end1-begin1+1;
}
}
if(s1[begin1] == s2[begin2])
{
return dis(s1, begin1+1, end1, s2, begin2+1, end2);
}
else
{
int t1 = dis(s1, begin1+1, end1, s2, begin2, end2);
int t2 = dis(s1, begin1, end1, s2, begin2+1, end2);
int t3 = dis(s1, begin1+1, end1, s2, begin2+1, end2);
t1 = t1<t2?t1:t2;
t3 = t1<t3?t1:t3;
return t3+1;
}
}
void main()
{
char s1[] = "ABC";
char s2[] = "CBCD";
int result = dis(s1, 0, 3, s2, 0, 4);
printf("%d", result);
}
编辑距离(递归)
最新推荐文章于 2024-09-05 16:09:54 发布