• 题意
    • 问字符串是否满足ABABA或ABABCAB的形式
  • 题解
    • 直接暴力,暴力方式有多种
    • 可以直接隔板判断,但是这样复杂度过高
    • 所以我们枚举用substr枚举A与B (substr(开始的地方,字符串的个数))
      • ABABA
        • 二重循环用substr生成A,B
        • 然后直接用string拼接成ABABA进行判断
      • ABABCAB
        • 二重循环生成A,B
        • 将AB合成一个串
        • substr((i+j)*2,len-(i+j)*3)取出C
        • 然后拼接判断
  • 代码
    • #include<algorithm>
      #include <iostream>
      #include   <fstream>
      #include  <cstdlib>
      #include  <cstring>
      #include  <cassert>
      #include   <cstdio>
      #include   <vector>
      #include   <string>
      #include    <cmath>
      #include    <queue>
      #include    <stack>
      #include      <set>
      #include      <map>
      using namespace std;
      #define P(a,b,c) make_pair(a,make_pair(b,c))
      #define rep(i,a,n) for (int i=a;i<=n;i++)
      #define per(i,a,n) for (int i=n;i>=a;i--)
      #define CLR(vis) memset(vis,0,sizeof(vis))
      #define MST(vis,pos) memset(vis,pos,sizeof(vis))
      #define pb push_back
      #define mp make_pair
      #define all(x) (x).begin(),(x).end()
      #define fi first
      #define se second
      #define SZ(x) ((int)(x).size())
      typedef pair<int,pair<int,int> >pii;
      typedef long long ll;
      typedef unsigned long long ull;
      const ll mod = 1000000007;
      const int INF = 0x3f3f3f3f;
      ll gcd(ll a, ll b) {
      	return b ? gcd(b, a%b) : a;
      }
      template<class T>inline void gmax(T &A, T B) {
      	(A<B)&&(A=B);//if(B>A)A=B;
      }
      template<class T>inline void gmin(T &A, T B) {
      	(A>B)&&(A=B);//if(B<A)A=B;
      }
      template <class T>
      inline bool scan_d(T &ret) {
      	char c;
      	int sgn;
      	if(c=getchar(),c==EOF) return 0; //EOF
      	while(c!='-'&&(c<'0'||c>'9')) c=getchar();
      	sgn=(c=='-')?-1:1;
      	ret=(c=='-')?0:(c-'0');
      	while(c=getchar(),c>='0'&&c<='9') ret=ret*10+(c-'0');
      	ret*=sgn;
      	return 1;
      }
      inline void outt(int x) {
      	if(x>9) outt(x/10);
      	putchar(x%10+'0');
      }
      const int MAXN = 1e6+10;
      
      int main() {
      	int t;
      	char ch[100];
      	scanf("%d", &t);
      	while(t--) {
      		string str;
      		scanf("%s", ch);
      		int len = strlen(ch);
      		rep(i,0,len-1) {
      			if ( isalpha(ch[i]) ) {
      				str += ch[i];
      			}
      		}
      
      		len = str.length();
      		int flag = 0;
      		for (int i = 1; i < len/2; i++) {
      			if(flag)break;
      			for (int j = 1; j < len/2; j++) {
      				if(flag)break;
      				string A = str.substr(0, i);
      				string B = str.substr(i, j);
      				if (A == B) {
      					continue;
      				}
      				if (A + B + A + B + A == str) {
      					flag = 1;
      					continue;
      				}
      				if (len - (i + j) * 3 > 0) {
      					string AB = A + B;
      					string C = str.substr(2*(i+j), len-3*(i+j));
      					if (A == C || B == C) {
      						continue;
      					}
      					if (AB + AB + C + AB == str) {
      						flag = 1;
      						continue;
      					}
      				}
      			}
      		}
      		printf( flag ? "Yes\n" : "No\n" );
      	}
      	return 0;
      }
      

发表评论

邮箱地址不会被公开。 必填项已用*标注