当前你的浏览器版本过低,网站已在兼容模式下运行,兼容模式仅提供最小功能支持,网站样式可能显示不正常。
请尽快升级浏览器以体验网站在线编辑、在线运行等功能。

建议使用的浏览器:

谷歌Chrome 火狐Firefox Opera浏览器 微软Edge浏览器 QQ浏览器 360浏览器 傲游浏览器

6629:string matching

题目描述
String matching is a common type of problem in computer science. One string matching problem is as following:

Given a string $s[0 \ldots len-1]$, please calculate the length of the longest common prefix of $s[i \ldots len-1]$ and $s[0 \ldots len-1]$ for each $i > 0$.

I believe everyone can do it by brute force.
The pseudo code of the brute force approach is as the following:



We are wondering, for any given string, what is the number of compare operations invoked if we use the above algorithm. Please tell us the answer before we attempt to run this algorithm.
输入解释
The first line contains an integer $T$, denoting the number of test cases.
Each test case contains one string in a line consisting of printable ASCII characters except space.

* $1 \le T \le 30$

* string length $\le 10^6$ for every string
输出解释
For each test, print an integer in one line indicating the number of compare operations invoked if we run the algorithm in the statement against the input string.
输入样例
3
_Happy_New_Year_
ywwyww
zjczzzjczjczzzjc
输出样例
17
7
32
来自杭电HDUOJ的附加信息
Recommend liuyiding

该题目是Virtual Judge题目,来自 杭电HDUOJ

源链接: HDU-6629

最后修改于 2020-10-25T23:32:59+00:00 由爬虫自动更新

共提交 0

通过率 --%
时间上限 内存上限
2000/1000MS(Java/Others) 262144/262144K(Java/Others)