-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathedit.cpp
More file actions
35 lines (30 loc) · 771 Bytes
/
edit.cpp
File metadata and controls
35 lines (30 loc) · 771 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#include "edit.h"
//#include<bits/stdc++.h>
//using namespace std;
int edit(string s1, int m, string s2, int n){
int ed[m+1][n+1];
for(int i=0; i<=m; i++){
for(int j=0; j<=n; j++){
if(i==0){
ed[i][j]=j;
}
else if(j==0){
ed[i][j]=i;
}
else if(s1[i-1]==s2[j-1]){
ed[i][j]=ed[i-1][j-1];
}
else{
ed[i][j]=min(min(ed[i-1][j],ed[i][j-1]),ed[i-1][j-1])+1;
}
}
}
return ed[m][n];
}
//int main(){
// string s1,s2;
// cout<<"Enter two words:";
// cin>>s1>>s2;
// cout<<"Edit distance:"<<edit(s1,s1.length(),s2,s2.length());
// return 0;
//}