#include <stdio.h>
#include <string.h>
char S1[100], S2[100];
//最少値を求める
int min(int a, int b, int c)
{
return a > b ? (b > c ? c : b) : (a > c ? c : a);
}
int main()
{
scanf("%s", S1);
scanf("%s", S2);
//編集距離計算
int lenstr1 = strlen(S1) + 1;
int lenstr2 = strlen(S2) + 1;
int d[100][100];
int i1 = 0, i2 = 0, cost = 0;
for (; i1 < lenstr1; i1++) d[i1][0] = i1;
for (; i2 < lenstr2; i2++) d[0][i2] = i2;
for (i1 = 1; i1 < lenstr1; i1++) {
for (i2 = 1; i2 < lenstr2; i2++) {
cost = S1[i1 - 1] == S2[i2 - 1] ? 0 : 1;
d[i1][i2] = min(d[i1 - 1][i2] + 1, d[i1][i2 - 1] + 1, d[i1 - 1][i2 - 1] + cost);
}
}
printf("編集距離は%dです\n", d[lenstr1 - 1][lenstr2 - 1]);
}
例えば、あいうえお、いうえお、という文字列を比較した際、編集距離は1になるはずなのですが
2と表示されてしまいます。
ご教授お願い致します。