解题思路:因为长度不超过50,所以可以直接枚举A、B的长度,然后暴力求解。
代码如下:
#include <cstdio>
#include <iostream>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <string>
#include <algorithm>
#include <vector>
#include <deque>
#include <list>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <numeric>
#include <iomanip>
#include <bitset>
#include <sstream>
#include <fstream>
#include <limits.h>
#include <ctime>
#define debug "output for debug\n"
#define pi (acos(-1.0))
#define eps (1e-6)
#define inf (1<<28)
#define sqr(x) (x) * (x)
#define mod 1000000007
using namespace std;
typedef long long ll;
typedef unsigned long long ULL;
bool solve1(string s)
{
int i,j;
string sa,sb,sc,sd,se;
for(i=1; 3*i<=s.size(); i++)
{
for(j=1; i+j+i+j+i<=s.size(); j++)
{
if((i+j+i+j+i)!=s.size())
continue;
sa.clear();sb.clear();sc.clear();sd.clear();se.clear();
sa.assign(s,0,i);//A
sb.assign(s,i,j);//B
sc.assign(s,i+j,i);//A
sd.assign(s,i+j+i,j);//B
se.assign(s,i+j+i+j,i);//A
//cout<<i<<" "<<j<<endl;
//cout<<sa<<" "<<sb<<" "<<sc<<" "<<sd<<" "<<se<<endl;
if(sa==sc&&sa==se&&sb==sd&&sa!=sb)
return 1;
}
}
return 0;
}
bool solve2(string s)
{
int i,j,k;
string sa,sb,sc,sd,se,sf,sg;
for(i=1; 3*i+3<=s.size(); i++)
{
for(j=1; i+j+i+j+i+j<=s.size(); j++)
{
for(k=1; i+j+i+j+k<=s.size(); k++)
{
if((i+j+i+j+k+i+j)!=s.size())
continue;
sa.clear();sb.clear();sc.clear();sd.clear();se.clear();sf.clear();sg.clear();
sa.assign(s,0,i);//A
sb.assign(s,i,j);//B
sc.assign(s,i+j,i);///A
sd.assign(s,i+j+i,j);///B
se.assign(s,i+j+i+j,k);///C
sf.assign(s,i+j+i+j+k,i);///A
sg.assign(s,i+j+i+j+k+i,j);///B
//cout<<sa<<" "<<sb<<" "<<sc<<" "<<sd<<" "<<se<<" "<<sf<<" "<<sg<<endl;
if(sa==sc&&sa==sf&&sb==sd&&sb==sg&&sa!=sb&&sa!=se&&sb!=se)
return 1;
}
}
}
return 0;
}
int main()
{
int i,j,k,t;
string s,s1;
scanf("%d",&t);
while(t--)
{
s1.clear();
s.clear();
cin>>s1;
for(i=0; i<s1.size(); i++)
{
if((s1[i]>='a'&&s1[i]<='z')||(s1[i]>='A'&&s1[i]<='Z'))
s+=s1[i];
}
if(solve1(s)||solve2(s))
printf("Yes\n");
else
printf("No\n");
//cout<<s<<endl;
}
return 0;
}