ZOJ3818

题意: 给一个字符串,判断它是否为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;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值