-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathuva-10405.cpp
More file actions
53 lines (40 loc) · 1.09 KB
/
uva-10405.cpp
File metadata and controls
53 lines (40 loc) · 1.09 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
#include <bits/stdc++.h>
using namespace std;
const int MAX = 1000;
int Length[MAX + 1][MAX + 1]; /// table for length
char A[MAX + 5];
char B[MAX + 5];
int main()
{
freopen("in.txt", "r", stdin);
freopen("out.txt", "w", stdout);
int n, m, i, j;
while (gets(A)) {
gets(B);
n = strlen(A);
m = strlen(B);
for (i = n; i >= 0; i--) {
A[i + 1] = A[i];
}
for (j = m; j >=0; j--) {
B[j + 1] = B[j];
}
for (i = 1; i <= n; i++) {
for (j = 1; j <= m; j++) {
if (A[i] == B[j]) {
Length[i][j] = Length[i - 1][j - 1] + 1;
}
else {
if (Length[i - 1][j] >= Length[i][j - 1]) {
Length[i][j] = Length[i - 1][j];
}
else {
Length[i][j] = Length[i][j - 1];
}
}
}
}
printf("%d\n", Length[n][m]);
}
return 0;
}