forked from arv002-zz/spojcodes
-
Notifications
You must be signed in to change notification settings - Fork 0
/
EDIST - Edit distance.cpp
59 lines (47 loc) · 1.01 KB
/
EDIST - Edit distance.cpp
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#include<iostream>
#include<bits/stdc++.h>
using namespace std;
long long Min(long long a, long long b, long long c)
{
if(a>b)
{
if(b<c)
return b;
else
return c;
}
else
{
if(a<c)
return a;
else
return c;
}
}
long long EditDistance(string a, string b, long long length1,long long length2)
{
int d;
if(length1==0)
return length2;
if(length2==0)
return length1;
if(a[length1 -1]==b[length2 -1])
d=0;
else
d=1;
return Min(EditDistance(a,b,length1-1,length2)+1,EditDistance(a,b,length1,length2-1)+1,EditDistance(a,b,length1-1,length2-1) +d
);
}
int main()
{
long long n,m,i,j,k,T;
cin>>T;
while(T--)
{
string a,b;
cin>>a>>b;
long long length1=a.length();
long long length2=b.length();
cout<<EditDistance(a,b,length1,length2);
}
}