UVa 455 periodic Strings (cycle string)

Source: Internet
Author: User

Periodic Strings
Time Limit: 3000MS Memory Limit: Unknown 64bit IO Format: %lld &%llu

Submit Status

Description

periodic Strings

A character string is said to has period K if it can be formed by concatenating one or more repetitions of anoth Er string of length K. For example, the string "abcabcabcabc" had period 3, since it was formed by 4 repetitions of the string "abc ". It also has periods 6 (both repetitions of "abcabc") and (one repetition of "abcabcabcabc").

Write a program to read a character string and determine its smallest period.

Input

The first line oif the input file would contain a single integer N indicating what many test case which your program would TES T followed by a blank line. Each of the test case would contain a single character string of Non-blank characters. Consecutive input would separated by a blank line.

Output

An integer denoting the smallest period of the input string for each input. The consecutive output is separated by a blank line.

Sample Input
1HoHoHo
Sample Output
2
Approximate test instructions: If a string can be repeated multiple times by a string of length k, it is said to have a period of K. The minimum period of the string to be given.
1#include <iostream>2#include <cstring>3 using namespacestd;4 intMain ()5 {6     intn,j;7Cin>>N;8      while(n--)9     {Ten         Chara[ +]; One         Charb[ +]; Ab[0]=' /'; -Cin>>A; - strcat (b,a); the strcat (b,a); -         intnum=strlen (a); -          for(intI=1; i<=num;i++) -         { +             intk=i; -             if(strncmp (b+i,a,num-i) = =0&& Num%k = =0 ) +             { Acout<<K; at                  Break; -             } -         } -         if(j!=N) -cout<<endl<<Endl; -         if(j==N) incout<<Endl; -     } to     return 0; +}

UVa 455 periodic Strings (cycle string)

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.