题意: 给一个字符串,判断它是否为ABABA或ABABCAB的形式
题解:枚举AB和C的长度,【坑】ABC都不能相同【被坑了好多次】,然后暴力判断是否符合要求即可
string.substr(i,l) --》取从第i位置长度为l的子串
#include <bits/stdc++.h>
using namespace std;
string::iterator it;
string a;
void Gao()
{
bool ans1=false,ans2=false;
a="";
getline(cin,a);
int t=1;
for (it=a.begin();it!=a.end();)
{
if ((*it<='z'&& *it>='a')||(*it<='Z'&& *it>='A'))
*it=toupper(*it),it++;
else
it=a.erase(it);
}
int len=a.size();
// ababa;
for (int i=1;i<=50;i++)
for (int j=1;j<25;j++)
{
if (3*i+2*j==len)
{
string t1,t2,t3,t4,t5;
t1=a.substr(0,i);
t2=a.substr(i,j);
t3=a.substr(i+j,i);
t4=a.substr(i+j+i,j);
t5=a.substr(i+j+i+j,i);
if (t1==t2)
continue;
if (t1==t3&&t3==t5 &&t2==t4)
ans1=true;//,cout<<t1<<" "<<t2<<" "<<t3<<" "<<t4<<" "<<t5<<endl;
}
}
for (int i=1;i<=50;i++)
for (int j=1;j<=50;j++)
for (int k=1;k<=50;k++)
{
if (3*i+3*j+k==len)
{
string t1,t2,t3,t4,t5,t6,t7;
t1=a.substr(0,i);//1
t2=a.substr(i,j);//2
t3=a.substr(i+j,i);//1
t4=a.substr(i+j+i,j);//2
t5=a.substr(i+j+i+j,k);//3
t6=a.substr(i+j+i+j+k,i);//1
t7=a.substr(i+j+i+j+k+i,j);//2
if (t1==t2||t2==t5||t3==t5)
continue;
if (t1==t3&&t3==t6 &&t2==t4&&t4==t7)
ans2=true;
//cout<<t1<< " "<<t2<<" "<<t3<<" "<<t4<<" "<<t5<<" "<<t6<<" "<<t7<<endl;
}
}
if (ans1||ans2)
cout<<"Yes"<<endl;
else
cout<<"No"<<endl;
}
int main()
{
int T;
//freopen("a.in","r",stdin);
cin>>T;
getchar();
while (T--)
Gao();
return 0;
}