-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEdit_Distance.cpp
More file actions
56 lines (56 loc) · 1.2 KB
/
Copy pathEdit_Distance.cpp
File metadata and controls
56 lines (56 loc) · 1.2 KB
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
//Edit_Distance.....
#include<cstdio>
#include<cctype>
#include<string>
#include<string.h>
#include<iostream>
#include<algorithm>
#include<cmath>
#include<cstdlib>
using namespace std;
#define s scanf
#define p printf
int main()
{
char x[10],y[10],c[10][10];
int mat[10][10],i,j,a,b;
while(s("%s %s",x,y)==2)
{
a=strlen(x);
b=strlen(y);
memset(mat,0,sizeof(mat));
for(i=1;i<=a;++i)
{
for(j=1;j<=b;++j)
{
if(x[i-1]==y[j-1])
{
mat[i][j]=mat[i-1][j-1];
c[i][j]='D';
}
else if(mat[i-1][j]>mat[i][j-1])
{
mat[i][j]=mat[i][j-1]+1;
c[i][j]='L';
}
else
{
mat[i][j]=mat[i-1][j]+1;
c[i][j]='U';
}
//printf(" %c ",c[i][j]);
}
//printf("\n");
}
p("%d\n\n",mat[a][b]);
}
return 0;
}
/*
GAMBOL GUMBO
3
ABDULLAH ABDALLAH
2
//ABCACABDC BACADCBAC
5
*/