calculate the distance of two string
来源:互联网 发布:php 框架 编辑:程序博客网 时间:2024/04/27 16:15
#include <iostream>#include <string>#include <fstream>using namespace std;#define MIN(x, y, z)((x < y) ? (x < z ? x : z) : (y < z ? y : z)) int calcStringDistance(const string &s1, int beg1, int end1, const string &s2, int beg2, int end2){if(beg1 > end1){if(beg2 > end2)return 0;elsereturn (end2-beg2+1);}if(beg2 > end2){if(beg1 > end1)return 0;elsereturn (end1-beg1+1);}if(s1[beg1] == s2[beg2])calcStringDistance(s1, beg1+1, end1, s2, beg2+1, end2);else{int d1 = calcStringDistance(s1, beg1+1, end1, s2, beg2, end2);int d2 = calcStringDistance(s1, beg1, end1, s2, beg2+1, end2);int d3 = calcStringDistance(s1, beg1+1, end1, s2, beg2+1, end2);return MIN(d1, d2, d3)+1;}}int main(){string s1 = "123450";string s2 = "012345";int distance = calcStringDistance(s1, 0, s1.size()-1, s2, 0, s2.size()-1);cout << distance <<endl;}
- calculate the distance of two string
- Calculate the distance between sets of vectors.
- Calculate the cycle of the string 字符串周期计算
- Calculate the Greatest Commom Divisor (GCD) and Lowest Common Multiple (LCP) of Two Integers
- calculate the length of char*
- Calculate the biggest sum of subarray
- Calculate the biggest sum of submatrix
- Calculate the area of dashed part
- calculate the square of a number
- Calculate the number of UTF8 characters
- LeetCode: Edit Distance of Two Words
- calculate distance within matlab
- Find the distance between two nodes
- Calculate difference between two dates (number of days) in C#?
- The distance attribute mean of DMatches
- the longest distance of a binary tree
- Calculate the CDF of Poisson Distribution with Boost C++ Library
- how to calculate the QR decomposition of a matrix
- QQ群信息统计
- Maya: 菜单 曲面 >双轨成形>双轨成形3+工具
- 试探算法
- Maya: 菜单 曲面 >边界
- 关于rsync同步命令的使用
- calculate the distance of two string
- Milking cows
- NSPR在Windows上编译及使用
- Maya: 菜单 曲面 >方形
- 海思SDK编译实践 -- hi3716cv200es1
- Java经典算法四十例编程详解+程序实例
- Tomcat服务器详解
- matlab矩阵操作常用函数
- 10905 - Children's Game