Power Strings

Posted qing123tian

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Power Strings相关的知识,希望对你有一定的参考价值。

Power Strings

题目描述

Given two strings a and b we define a*b to be their concatenation. For example, if a = "abc" and b = "def" then a*b = "abcdef". If we think of concatenation as multiplication, exponentiation by a non-negative integer is defined in the normal way: a^0 = "" (the empty string) and a^(n+1) = a*(a^n).
 

输入

Each test case is a line of input representing s, a string of printable characters. The length of s will be at least 1 and will not exceed 1 million characters. A line containing a period follows the last test case.
 

输出

For each s you should print the largest n such that s = a^n for some string a.
 

样例输入

abcd
aaaa
ababab
.

样例输出

1
4
3

技术图片
 1 #include<bits/stdc++.h>
 2 using namespace std;
 3 #define MAXN 1000017
 4 int Next[MAXN];
 5 int len;
 6 void getNext( char T[])
 7 
 8     int i = 0, j = -1;
 9     Next[0] = -1;
10     while(i <len)
11     
12         if(j == -1 || T[i] == T[j])
13         
14             i++,j++;
15             Next[i] = j;
16         
17         else
18             j = Next[j];
19     
20 
21 
22 int main()
23 
24     char ss[MAXN];
25     int length;
26     while(cin >> ss)
27     
28         if(ss[0] == .)
29             break;
30         len = strlen(ss);
31         getNext(ss);
32         length = len - Next[len];
33         if(len%length == 0)
34             cout << len/length << endl;
35         else
36             cout << "1" << endl;
37     
38     return 0;
39 
View Code

 

以上是关于Power Strings的主要内容,如果未能解决你的问题,请参考以下文章

乱想数学

Go 从入门到精通字符串,时间,流程控制,函数

微软电脑用power bi要钱吗

power BI如何取排名在20-40名的人?

power bi为什么同比不能横向排列

AlterDialog如何屏蔽power键??