编辑距离
求大神修改int getDistance(char s1,char s2)
{
int len1,len2;
len1=strlen(s1);
len2=strlen(s2);
int d[len1+1][len2+1];
int i=0;,j=0;
for(i=0;i<=len1;i++)
{
d[i][0]=i;
}
for(j=0;j<=len2;j++)
{
d[0][j]=j;
}
for(i=1;i<len1+1;i++)
{
for(j=1;j<len2+1;j++)
{
int cost = 1;
if(s1[i-1] == s2[j-1])
{
cost=0;
}
int delete=d[i-1][j]+1;
int insert=d[i][j-1]+1;
int substitution=d[i-1][j-1]+cost;
d[i][j]=min(delete,insert,substitution);
}
return(d[len1][len2]);
}
}
int min(int d,int i,int s)
{
int temp=0;
if(d>i)
temp=i;
else
temp=d;
return s<temp?s:temp;
}
main()
{
char s1[] = {"kitten"};
char s2[] ={"sitting"};
printf(getDistance(s1,s2));
}