Nanyang 264 (King's Magic Mirror)

Source: Internet
Author: User

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)

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.