参考:https://www.cnblogs.com/grenet/archive/2010/06/01/1748448.html
#include <iostream>
#include <string>
#include <stdio.h>
using namespace std;
//定义计算文本修改的操作次数类
class text_modify_num{
private:
char mA[100];
char mB[100];
public:
int Min_abc(int A, int B, int C)
{
int minvalue=A;
if(minvalue>B)
{
minvalue=B;
}
if(minvalue>C)
{
minvalue=C;
}
return minvalue;
}
int LD(string A,string B)
{
//字符串转换为字符数组
int lengthA=A.copy(mA,A.length());
mA[lengthA]='\0';
int lengthB=B.copy(mB,B.length());
mB[lengthB]='\0';
//定义结果变量
int L[A.length()][B.length()];
int i;
int j;
//初始化L
for(i=0;i<A.length();i++)
{
for(j=0;j<B.length();j++)
{
L[i][j]=0;
}
}
for(i=1;i<A.length();i++)
{
L[i][0] = i;
}
for(j=1;j<B.length();j++)
{
L[0][j] = j;
}
for(i=0;i<A.length();i++)
{
for(j=0;j<B.length();j++)
{
cout<<L[i][j];
}
cout<<endl;
}
//计算操作次数
for(i=1;i<A.length();i++)
{
for(j=1;j<B.length();j++)
{
if(mA[i-1]==mB[j-1])
{
L[i][j] = L[i - 1][j - 1];
}else{
L[i][j] = Min_abc(L[i - 1][j - 1], L[i - 1][j], L[i][j - 1]) + 1;
}
}
}
for(i=0;i<A.length();i++)
{
for(j=0;j<B.length();j++)
{
cout<<L[i][j];
}
cout<<endl;
}
return L[A.length()-1][B.length()-1];
}
};
int main()
{
text_modify_num text_check;
int num;
char word;
char ch;
cin>>num;
ch = getchar();
string str[num*2];
for(int p=0;p<num*2;p++)
{
while ((ch = getchar()) != '\n') {
str[p]=str[p]+(ch);
}
}
cout<<str[0]<<endl;
int modify_num=text_check.LD(str[0],str[1]);
cout<< modify_num;
return 0;
}