题目:计算两个字符串的最大公共子串的长度,子串不区分大小写
#include<iostream>
#include<string>
#include<cctype>
using namespace std;
int MaxSubstr(const string &a,const string &b)
{
int count=0,Max=0;
int start1,start2;
for(int i=0;i<a.size();i++)
for(int j=0;j<b.size();j++)
{
start1=i,start2=j;
while(a[start1]==b[start2] && start1<a.size() && start2<b.size())
{
count++;
start1++;
start2++;
}
if(count>Max)
Max=count;
count=0;
}
return Max;
}
int main()
{
string s1,s2;
cin>>s1>>s2;
for(int i=0;i<s1.size();i++)
s1[i]=tolower(s1[i]);
for(int i=0;i<s2.size();i++)
s2[i]=tolower(s2[i]);
cout<<MaxSubstr(s1,s2)<<endl;
}