264 the Magic mirror of the King

Source: Internet
Author: User

Describe
The
King has a magic mirror that can turn anything that touches the mirror twice times the original-just because it is a mirror, the added part is reversed.

Like a necklace, we use AB to indicate that different letters represent different colors of pearls. If the B end touches the mirror, the mirror will turn this necklace into ABBA. If the other end touches, it becomes abbaabba (assuming the king only touches the mirror with one end of the necklace).

Given the final necklace, write the program output the minimum length that the original necklace may be before the king does not use the magic mirror.

Input
The
first line is an integer N (n<=10) that represents the number of groups of test data)
Each group of test data occupies only one string (less than 100), consisting of uppercase English letters that represent the final necklace.
Output
the output of each set of test data has only one integer, indicating the smallest possible length of the original necklace before the king used the Magic mirror.
Sample input
2 Abbaabba A
Sample output
2 1
Analysis: This is a very interesting topic, the topic is not difficult, the key is to clear the idea, know the requirements of the topic, to see, odd is not, so the direct output length,
The code is as follows: #include "stdio.h"
Char Bei (char a[],int N)//Add function to determine if even is symmetric
{
      int i;
For (i=0;i less than n/2;i++)
          if (A[i]!=a[n-1-i])
             Break
         if (I!=N/2) return (0);
           else return (1);
}
#define P printf//Define macros to simplify writing ·
#define S scanf
Main ()
{
    Char s[105];
   int i,j,k,m,n;
S ("%d", &n); GetChar ();
  while (n--)
     {
              int A;
         Gets (s);
               for (i=0;s[i]!= ' n '; i++); m=i;
           while (1) {
                      if (m%2==1)
                               {P ("%d\n", m); break;}
                           Else
                           {if (Bei (s,m))//Use function return value to determine symmetry
                              M=M/2;
                          Else
                          {P ("%d\n", m); break;}}
                }}}

264 the Magic mirror of the King

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.