#include<iostream>
#include<string>
#include<cstdlib>
using namespace std;
string getLongest(string s)
{
int n = s.length();
if(n<=1)
return s;
int start = 0;
int count = 1;
int max = 1;
char flag = tolower(s[0]);
for(int i=1;i<n;i++)
{
if(tolower(s[i])==flag)
{
++count;
flag = tolower(s[i]);
}else{
if(max<count)
{
max = count;
start = i-max;
}
count = 1;
flag = tolower(s[i]);
}
}
// cout<<max<<endl;
// cout<<count<<endl;
// cout<<start<<endl;
if(max<count)
{
max = count;
start = n-max;
}
return s.substr(start,max);
}
int main()
{
string s;
cin>>s;
cout<<getLongest(s)<<endl;
return 0;
}
求一个字符串中最长的相同字符字串 不区分大小写
最新推荐文章于 2022-10-28 10:47:34 发布