Nyoj--264 King's Magic Mirror "water Problem"

Source: Internet
Author: User
Tags min time limit
the Magic Mirror of the KingTime limit: Ms | Memory limit: 65535 KB Difficulty: 1 Description 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. Enter 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 of each set of test data has only one integer, indicating the minimum length of the original necklace that the king did not use before the magic mirror. Sample input

2
Abbaabba
A
Sample output
2
1

If the length of the string is odd, then directly output its length, if it is even, to see if it is a palindrome string, if so, then the length of half, in the view is a palindrome string, has been circulating to no palindrome string or the length is odd.

#include <cstdio>
#include <cstring>
#include <iostream>
using namespace std;
Char str[110];

int change (int len) {
	int i=0,j=len-1;
	while (i<j) {
		if (Str[i]!=str[j])
			return 0;
		i++;j--;
	}
	return 1;
}

int main () {
    int t;
    cin>>t;
    while (t--) {
        cin>>str;
        int Len=strlen (str);
        while (!) ( len&1) && Change (len)
            len/=2;
        cout<<len<<endl;
    }
    return 0;
}


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.