#include<iostream>
#include<string>
#include<algorithm>
using namespace std;
const int maxn = 110;
int dp[maxn][maxn];
int main() {
string s1, s2;
cin >> s1 >> s2;
for (int i = 1; i < s1.length(); i++)
dp[i][0] = i;
for (int j = 1; j < s2.length(); j++)
dp[0][j] = j;
for (int i = 1; i <= s1.length(); i++) {
for (int j = 1; j <= s2.length(); j++) {
if (s1[i-1] == s2[j-1])
dp[i][j] = dp[i - 1][j - 1];
else {
int temp = min(dp[i - 1][j] + 1, dp[i][j - 1] + 1);
dp[i][j] = min(temp, dp[i - 1][j - 1] + 1);
}
}
}
cout << dp[s1.length()][s2.length()];
system("pause");
return 0;
}
编辑距离(双序列)
最新推荐文章于 2024-09-07 23:15:53 发布