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;}