NYOJ 264 King's Magic Mirror

Source: Internet
Author: User

King magic mirror time limit: 3000 MS | memory limit: 65535 KB difficulty: 1

Description
The King has a magic mirror, which can double any contact with the mirror-only, because it is a mirror, the added part is reversed.

For example, we use AB to represent a necklace. Different letters represent pearls of different colors. If the B side is exposed to the mirror, the magic mirror will change this necklace to ABBA. If one end is used, it will become ABBAABBA (assuming that the king only uses one end of the necklace to access the magic mirror ).

Given the final necklace, write a program to output the minimum possible length of the initial necklace before the king uses the magic mirror.

Input
The first line is an integer N (N <= 10) indicating the number of test data groups)
Each group of test data occupies only one string (less than 100 characters in length) in one row, consisting of uppercase letters, indicating the final necklace.
Output
The output of each group of test data has only one integer, indicating the minimum possible length of the initial necklace before the king uses the magic mirror.
Sample Input
2ABBAABBAA
Sample output
21
The details cannot be noticed!
Ac code:
#include
      
       #include
       
        char ch[105];int fun(int len){if(len<=1)return 0;int i=len/2,j=(len/2-1);while((i
        
         =0)){if(ch[i]!=ch[j])return 0;i++;j--;}if((i==len)&&(j==-1))return 1;elsereturn 0;}int main(){int n;scanf("%d",&n);while(n--){scanf("%s",ch);int len=strlen(ch);while(fun(len)){len=len/2;}printf("%d\n",len);}return 0;}
        
       
      


Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.