-
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