#include <iostream>
#include <string>
using namespace std;
int main()
{
string s1;
string s2;
string s3;
string *sp1;
string *sp2;
string *minp;
cin>>s1>>s2>>s3;
if(s1.length()> s2.length())
{
sp1 = &s1;
sp2 = &s2;
}else
{
sp1 = &s2;
sp2 = &s1;
}
if(sp2->length()>s3.length())
{
minp = &s3;
}else
{
minp = sp2;
sp2 = &s3;
}
int max = 0;
int start = 0;
int length = minp->length();
for(int i = 0; i < length; ++i )
{
int templen = length - i;
for(int n = max; n < templen; ++n)
{
if((sp1->find(minp->substr(i, n))!=string::npos) && (sp2->find(minp->substr(i, n))!= string::npos))
{
if(n > max)
{
max = n;
start = i;
}
}else
{
break;
}
}
}
cout<<minp->substr(start, max);
return 0;
}
输入3个子串, 输出这3个子串的最大公共子串
最新推荐文章于 2022-11-28 17:18:52 发布