-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathLongestSubstringCommon.cpp
More file actions
69 lines (56 loc) · 1.28 KB
/
LongestSubstringCommon.cpp
File metadata and controls
69 lines (56 loc) · 1.28 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
#include<iostream>
#include<string>
#include<bits/stdc++.h>
using namespace std;
int main()
{
int t,i,j,n1,n2,maxi,num,x,y;
cin>>t;
while(t--)
{
cin>>x>>y;
maxi=0;
vector<string>s1;
vector<string>s2;
string str1,str2,st,sd;
cin>>str1>>str2;
/* for(i=0;i<3;i++){
cin>>st;
s1.push_back(st);
}*/
n1=str1.size();
n2=str2.size();
for(i=0; i<n1; i++)
{
for(j=1; j<=n1-i; j++)
{
st=str1.substr(i,j);
s1.push_back(st);
}
}
for(i=0; i<n2; i++)
{
for(j=1; j<=n2-i; j++)
{
st=str2.substr(i,j);
s2.push_back(st);
}
}
for(i=0; i<s1.size(); i++)
{
// cout<<"s1[i]"<<s1[i]<<endl;
for(j=0; j<s2.size(); j++)
{
// cout<<"s2[j]"<<s2[j]<<endl;
//num=s1[i].compare(s2[j]);
if(s1[i]==s2[j] && (s1[i].size())>maxi)
{
maxi=s1[i].size();
sd=s1[i];
}
}
}
cout<<maxi<<endl;
// cout<<"string"<<sd<<endl;
}
}