洛谷 P2799 国王的魔镜

      把项链当做字符串输进去,可以用gets

#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
using namespace std;
char a[100000];
int fj(int);
int main()
{
         gets(a);
         int len=strlen(a);
         fj(len);
         return 0;
}
int fj(int x)
{
        int m=x/2;
        if(x%2!=0)                //如果项链不能被2整除,证明项链没有被施法。。。
        {
             cout<<x;
              return x;
        }

        else
        {
             for(int i=0,j=x-1;i<m;i++,j--)
            {
                 if(a[i]!=a[j])                      //如果无法对称
                 {
                       cout<<x;
                       return x;
                 }

             }
          }
        fj(m);             //符合第一层要求,递归,继续拆分
}

猜你喜欢

转载自www.cnblogs.com/xiaoyezi-wink/p/10404004.html