字符串编辑距离
真言
学如逆水行舟,不进则退
引言
这是我第二次做九章算法的题目,是第一次写他题目的代码。他的题目很好,很新颖,与时俱进。
题目
有两个字符串A和B,对A可以进行如下的操作: 插入一个字符,删除一个字符,替换一个字符。 问A可以通过最少多少次操作变为B? 我们定义这个结果为字符串的最小编辑距离。
思路(借鉴九章算法的,感觉挺好,所以实现,共同学习)
字符串编辑距离归为DP题目,所以还是超好的
实验
代码
test.cpp
#include#include using namespace std; // get the minest number of three numbers int min(int a,int b,int c); // get the minest distance of string a and b int zifuchuan_bianji_juli(string a,string b); int main() { string a,b; cout<<"please input string a and b"< >a>>b; cout<<"a=\""< b) { if(b>c) return c; else return b; }else if(a>c) return c; else return a; }