Created
June 27, 2016 03:25
-
-
Save taznica/ecdeda072f4e1286b514cae1b8089fcb to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <string.h> | |
int min3(int a, int b, int c) | |
{ | |
int temp; | |
if(b>c) | |
{ | |
temp=b; | |
b=c; | |
c=temp; | |
} | |
if(a>b) | |
{ | |
temp=a; | |
a=b; | |
b=temp; | |
} | |
return a; | |
} | |
int ld(char *X, int m, char *Y, int n) | |
{ | |
int delta; | |
if(m==0 || n==0) | |
{ | |
if(m>0) | |
{ | |
return m; | |
} | |
else | |
{ | |
return n; | |
} | |
} | |
else | |
{ | |
if(X[m-1]==Y[n-1]) | |
{ | |
delta=0; | |
} | |
else | |
{ | |
delta=1; | |
} | |
return min3(ld(X, m-1, Y, n-1)+delta, | |
ld(X, m-1, Y, n)+1, | |
ld(X, m, Y, n-1)+1); | |
} | |
} | |
int main() | |
{ | |
char X[100], Y[100]; | |
int m, n, C; | |
scanf("%s", X); | |
scanf("%s", Y); | |
m=strlen(X); | |
n=strlen(Y); | |
C=ld(X, m, Y, n); | |
printf("%d\n", C); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment