Time limit of the King's Magic Mirror:MS | Memory limit:65535 KB Difficulty:1
-
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 Abbaabbaa
-
-
Sample output
-
-
2 1
-
-
Source
-
-
2008 Pupils Program design friendly test
-
-
//After mirror symmetry, the number of elements of the array must be an even number;
-
-
1#include <stdio.h>2#include <string.h>3 intMain ()4 {5 intm;6scanf"%d",&m);7 while(m--)8 {9 Charstr[ -];Tenscanf"%s", str); One intlen=strlen (str); A if(len%2==1) -printf"%d\n", Len); - Else the { - while(len!=0) - { - intj,k,b=0; + for(j=0, k=len-1; j<len/2; j++,k--) - { + if(str[j]==Str[k]) Ab++; at } - if(b==len/2) - { -Len/=2; - if(len%2==1) - { inprintf"%d\n", Len); - Break; to } + } - Else the { *printf"%d\n", Len); $ Break;Panax Notoginseng } - } the } + } A return 0; the}
Head, fuck!!.
Nanyang 264 (King's Magic Mirror)