-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy path10100.cpp
More file actions
80 lines (76 loc) · 1.3 KB
/
10100.cpp
File metadata and controls
80 lines (76 loc) · 1.3 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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
#include<stdio.h>
#include<string.h>
#define si 1050
char ch1[si][30],ch2[si][30];
char st1[si],st2[si],st[30];
long i,j,k=1,l1,l2,n,m,a,fg;
long ar[si][si];
long max(long a,long b)
{
if(a>b)
return a;
else return b;
}
int main()
{
while(gets(st1))
{
fg=0;
l1=strlen(st1);
gets(st2);
l2=strlen(st2);
if(l1==0||l2==0)
fg=1;
if(fg)
{
printf("%2ld. Blank!\n",k++);
continue;
}
i=0;j=0;
while(i<l1)
{
if((st1[i]>=65&&st1[i]<=90)||(st1[i]>=97&&st1[i]<=122)||st1[i]>=48&&st1[i]<=57)
{
st[a++]=st1[i];
if(st1[i+1]<48||(st1[i+1]>57&&st1[i+1]<65)||st1[i+1]>122||(st1[i+1]>90&&st1[i+1]<97))
{
st[a]=0;
strcpy(ch1[j++],st);
a=0;
}
}
i++;
}
m=j;
j=a=i=0;
while(i<l2)
{
if((st2[i]>=65&&st2[i]<=90)||(st2[i]>=97&&st2[i]<=122)||(st2[i]>=48&&st2[i]<=57))
{
st[a++]=st2[i];
if(st2[i+1]<48||(st2[i+1]>57&&st2[i+1]<65)||st2[i+1]>122||(st2[i+1]>90&&st2[i+1]<97))
{
st[a]=0;
strcpy(ch2[j++],st);
a=0;
}
}
i++;
}
n=j;
for(i=0;i<=m;i++)
{
for(j=0;j<=n;j++)
{
if(i==0||j==0)
ar[i][j]=0;
else if(strcmp(ch1[i-1],ch2[j-1])==0)
ar[i][j]=ar[i-1][j-1]+1;
else
ar[i][j]=max(ar[i][j-1],ar[i-1][j]);
}
}
printf("%2ld. Length of longest match: %ld\n",k++,ar[m][n]);
}
return 0;
}