fork(2) download
  1. #include<iostream>
  2. #include<string.h>
  3. using namespace std;
  4. int min(int a,int b)
  5. {
  6. return a>b?b:a;
  7. }
  8. int min(int a,int b,int c)
  9. {
  10. return min((min(a,b)),c);
  11. }
  12. int fun(char st1[],char st2[],int i,int j,int h1,int h2)
  13. {
  14. if((i>h1)&&(j>h2))
  15. return 0;
  16. if(i>h1)
  17. return (h2-j+1);
  18. if(j>h2)
  19. return (h1-i+1);
  20. if(st1[i]==st2[j])
  21. return (fun(st1,st2,i+1,j+1,h1,h2));
  22. else
  23. return min((1+fun(st1,st2,i+1,j,h1,h2)),
  24. (1+fun(st1,st2,i,j+1,h1,h2)),
  25. (1+fun(st1,st2,i+1,j+1,h1,h2)));
  26.  
  27. }
  28. int main()
  29. {
  30. char st1[]="geks";
  31. char st2[]="gekpss";
  32. cout<<fun(st1,st2,0,0,strlen(st1)-1,strlen(st2)-1);
  33. return 0;
  34. }
Success #stdin #stdout 0s 3340KB
stdin
Standard input is empty
stdout
2