Guest User

Untitled

a guest
Jul 23rd, 2020
79
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. EDIT DISTANCE CODE
  2. #include <iostream>
  3.  
  4. using namespace std;
  5.  
  6. int main()
  7. {
  8. string a,b;
  9. cin>>a;
  10. cin>>b;
  11. int n,m;
  12. n=a.length();m=b.length();
  13. int pre[n+1][m+1],i,j;
  14. for(i=0;i<=n;i++){for(j=0;j<=m;j++){pre[i][j]=7*(n+m);}}
  15. pre[0][0]=0;pre[0][1]=0;pre[1][0]=0;
  16. for(i=0;i<n;i++)
  17. {
  18. for(j=0;j<m;j++)
  19. {
  20. pre[i+1][j+1]=min(pre[i+1][j+1],pre[i+1][j]+1);
  21. pre[i+1][j+1]=min(pre[i+1][j+1],pre[i][j+1]+1);
  22. pre[i+1][j+1]=min(pre[i+1][j+1],pre[i][j]+(a[i]!=b[j]));
  23. }
  24. }
  25. cout<<pre[n][m];
  26.  
  27. return 0;
  28. }
RAW Paste Data