-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlcs.cpp
More file actions
38 lines (37 loc) · 802 Bytes
/
Copy pathlcs.cpp
File metadata and controls
38 lines (37 loc) · 802 Bytes
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
#include<bits/stdc++.h>
using namespace std;
#define ll long long
ll a[1001][1001];
int main()
{
char s[1001],s1[1001];
ll n,i,j,m,t=1,l,l1;
while(gets(s))
{
gets(s1);
memset(a,0,sizeof(a));
l=strlen(s);
l1=strlen(s1);
if(strlen(s)==0||strlen(s1)==0)
{
cout<<"0"<<endl;
continue;
}
for(i=0; i<l; i++)
{
for(j=0; j<l1; j++)
{
if(s[i]==s1[j])
{
a[i+1][j+1]=a[i][j]+1;
}
else
{
a[i+1][j+1]=max(a[i+1][j],a[i][j+1]);
}
}
}
cout<<a[l][l1]<<endl;
}
return 0;
}