-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path46.cpp
More file actions
31 lines (30 loc) · 721 Bytes
/
46.cpp
File metadata and controls
31 lines (30 loc) · 721 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
#include <bits/stdc++.h>
#include <iostream>
using namespace std;
int main(){
//program to find edit distance between two strings.
string s;
cin>>s;
string t;
cin>>t;
int m = s.length();
int n = t.length();
int arr[m+1][n+1];
for(int i=0;i<=m;i++){
for(int j=0;j<=m;j++){
if(i==0){
arr[i][j] = j;
}else if(j==0){
arr[i][j] = i;
}else if(s[i]==t[j]){
arr[i][j] = arr[i-1][j-1];
}
else{
arr[i][j] = min(arr[i-1][j-1], min(arr[i-1][j], arr[i][j-1]));
arr[i][j] += 1;
}
}
}
cout<<arr[m][n]<<endl;
return 0;
}