找最长串联字串的长度
#include<iostream>
#include<algorithm>
#include<cstring>
#include<queue>
#include<vector>
#include<map>
using namespace std;
typedef pair<int,int>PII;
typedef long long ll;
const int N=2e5+10;
ll a[N];
int main()
{
int t;cin>>t;
while(t--)
{
string s;cin>>s;
int ans=0;
for(int k=1;k*2<=s.size();k++)
{
int cnt=0;
for(int i=0;i+k<s.size();i++)
{
if(s[i]==s[i+k]||s[i]=='?'||s[i+k]=='?') cnt++;
else cnt=0;
if(cnt==k)
{
ans=k;
break;
}
}
}
cout<<2*ans<<endl;
}
return 0;
}
#include<iostream>
#include<algorithm>
#include<cstring>
#include<queue>
#include<vector>
#include<map>
using namespace std;
typedef pair<int,int>PII;
typedef long long ll;
const int N=2e5+10;
ll a[N];
int main()
{
int t;cin>>t;
while(t--)
{
string s;cin>>s;
int ans=0;
for(int x=2;x<=s.size();x+=2)
{
int ok=0;
int y=x/2;
for(int i=0;i<y;i++)
{
if(s[i]==s[i+y]||s[i]=='?'||s[i+y]=='?') ok++;
}
if(ok==y)
{
ans=x;
continue;
}
for(int i=0;i<s.size();i++)
{
int r=i+x;
if(r>s.size()) break;
if(s[i]==s[i+y]||s[i]=='?'||s[i+y]=='?') ok--;
if(s[r]==s[r-y]||s[r]=='?'||s[r-y]=='?') ok++;
if(ok==y)
{
ans=x;
break;
}
}
}
cout<<ans<<endl;
}
return 0;
}