字符串水题。
直接暴力查找。
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <queue>
#include <stack>
#include <cmath>
#include <cstdlib>
#include <vector>
#include <map>
#include <iostream>
using namespace std;
char str[100], stp[100];
bool check_ABABA(int len)
{
string mat = stp;
for(int i = 1; i < len; i++)
{
int l_AB = len - i;
if(l_AB % 2 == 1)
continue;
int l_B = l_AB / 2 - i;
if(l_B <= 0) break;
string A = mat.substr(0, i);
string B = mat.substr(i, l_B);
if(A == B || mat != A + B + A + B + A)
continue;
else return true;
}
return false;
}
bool check_ABABCAB(int len)
{
string mat = stp;
for(int i = 2; i < len; i++)
{
if(i * 3 >= len) break;
for(int j = 1; j < i; j++)
{
string A = mat.substr(0, j);
string B = mat.substr(j, i - j);
string C = mat.substr(2 * i, len - 3 * i);
if(A == B || B == C || A == C || mat != A + B + A + B + C + A + B)
continue;
else return true;
}
}
return false;
}
int main()
{
int t;
cin >> t;
while(t--)
{
cin>>str;
int len = 0;
for(int i = 0; str[i]; i++)
{
if(('a' <= str[i] && str[i] <= 'z') || ('A' <= str[i] && str[i] <= 'Z'))
{
stp[len++] = str[i];
}
}
stp[len] = '\0';
if(check_ABABA(len) || check_ABABCAB(len))
cout << "Yes\n";
else cout << "No\n";
}
}