#include<iostream>
#include<string>
using namespace std;
void Count(string A,string B,int lenA,int lenB)
{
int D[lenB+1][lenA+1];
int i,j;
int a=0,b=0;
for(i=0;i<=lenA;i++)
{
D[0][i]=i;
}
for(i=0;i<=lenB;i++)
{
D[i][0]=i;
}
for(i=1;i<=lenB;i++)
{
for(j=1;j<=lenA;j++){
if(A[j-1]==B[i-1]) a=D[i-1][j-1];
else a=D[i-1][j-1]+1;
if(D[i-1][j]+1>=D[i][j-1]+1) b=D[i][j-1]+1;
else b=D[i-1][j]+1;
if(a>b) D[i][j]=b;
else D[i][j]=a;
}
}
cout<< D[lenB][lenA];
}
int main()
{
string A,B;
cin>>A>>B;
int lenA = A.length();
int lenB = B.length();
Count(A,B,lenA,lenB);
}
编辑距离问题
最新推荐文章于 2024-09-05 23:50:23 发布