-
Notifications
You must be signed in to change notification settings - Fork 1
/
10100.cpp
84 lines (80 loc) · 1.24 KB
/
10100.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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#include<stdio.h>
#include<string.h>
int lcs[10100][10100];
char str1[1010], str2[10100];
char s1[10100][10100], s2[10100][10100];
int sz1, sz2, l1, l2;
int isChar(char ch)
{
return ((ch>='a' && ch<='z') || (ch>='A' && ch<='Z') || (ch>='0' && ch<='9'));
}
char to_lower(char ch)
{
if(ch>='A' && ch<='Z')
return ch+32;
return ch;
}
void cvnt();
int max(int a, int b)
{
if(a<b)
return b;
return a;
}
int main()
{
int i, j, C=1;
while(gets(str1))
{
gets(str2);
cvnt();
for(i=0; i<sz1; i++)
{
for(j=0; j<sz2; j++)
{
if(i>0 && j>0)
{
if( !strcmp(s1[i],s2[j]) )
lcs[i][j] = lcs[i-1][j-1] + 1;
else
lcs[i][j] = max(lcs[i-1][j], lcs[i][j-1]);
}else{lcs[i][j] = 0;}
}
}
if(!l1 || !l2)
printf("%2d. Blank!\n", C++);
else
printf("%2d. Length of longest match: %d\n", C++, lcs[sz1-1][sz2-1]);
}
return 0;
}
void cvnt()
{
int i, j;
l1 = strlen(str1);
sz1 = 1;
for(i=0; i<l1; i++)
{
j = 0;
if(isChar(str1[i]))
{
do{
s1[sz1][j++] = str1[i++];
}while(isChar(str1[i]));
s1[sz1++][j] = '\0';
}
}
l2 = strlen(str2);
sz2 = 1;
for(i=0; i<l2; i++)
{
j = 0;
if(isChar(str2[i]))
{
do{
s2[sz2][j++] = str2[i++];
}while(isChar(str2[i]));
s2[sz2++][j] = '\0';
}
}
}