#include<stdio.h>
#include<cmath>
#include<string.h>
const int maxn=100;
int d[maxn][maxn];
const int k=2;
int cmp(char a,char b)
{
return abs(a-b);
}
int DP(char a[],char b[])
{
int len1=strlen(a);
int len2=strlen(b);
d[0][0]=0;
int temp;
for(int i=1;i<=len1-1;i++)//赋初值
d[i][0]=k+d[i-1][0];
for(int j=1;j<=len2-1;j++)
d[0][j]=k+d[0][j-1];
for(i=1;i<=len1-1;i++)
for(j=1;j<=len2-1;j++)
{
d[i][j]=d[i-1][j]+k;
temp=d[i][j-1]+k;
if(temp<d[i][j])
d[i][j]=temp;
temp=d[i-1][j-1]+cmp(a[i],b[j]);
if(d[i][j]>temp)
d[i][j]=temp;
}
return d[len1-1][len2-1];
}
int main()
{
freopen("input.txt","r",stdin);
freopen("output.txt","w",stdout);
char a[maxn],b[maxn];
gets(a);
getchar();//吸收换行符
gets(b);
printf("%d\n",DP(a,b));
return 0;
}
#include<cmath>
#include<string.h>
const int maxn=100;
int d[maxn][maxn];
const int k=2;
int cmp(char a,char b)
{
return abs(a-b);
}
int DP(char a[],char b[])
{
int len1=strlen(a);
int len2=strlen(b);
d[0][0]=0;
int temp;
for(int i=1;i<=len1-1;i++)//赋初值
d[i][0]=k+d[i-1][0];
for(int j=1;j<=len2-1;j++)
d[0][j]=k+d[0][j-1];
for(i=1;i<=len1-1;i++)
for(j=1;j<=len2-1;j++)
{
d[i][j]=d[i-1][j]+k;
temp=d[i][j-1]+k;
if(temp<d[i][j])
d[i][j]=temp;
temp=d[i-1][j-1]+cmp(a[i],b[j]);
if(d[i][j]>temp)
d[i][j]=temp;
}
return d[len1-1][len2-1];
}
int main()
{
freopen("input.txt","r",stdin);
freopen("output.txt","w",stdout);
char a[maxn],b[maxn];
gets(a);
getchar();//吸收换行符
gets(b);
printf("%d\n",DP(a,b));
return 0;
}