-->
当前位置:首页 > 题库

PROGRAMMING:Small h string

Luz5年前 (2021-05-10)题库340
String matching is a common problem in computer science. A string matching problem is as follows:
Given the string $$s [0... Len-1] $, calculate the length of the longest common prefix of $$s [I... Len-1] $$and $$s [0... Len-1] $$for each $$I > 0 $$.
I believe everyone can do it with brute force. The pseudo code of brute force cracking method is as follows:
![ 2.png](~/22c331ab-970a-4b6b-9f88-9e078ae45b82.png)
We want to know how many comparison operations are called for any given string if the above algorithm is used. Please tell us the answer before trying to run this algorithm.
###Input format:
The first line contains an integer t that represents the number of test cases.
Each test case contains a string in one line, which consists of printable ASCII characters (except spaces).
* $$1\le T\le 30$$
*Length of each string $$\ le10 ^ 6$$
###Output format:
For each test, if we run the word algorithm on the input string, we print an integer on a line to indicate the number of comparison operations called.
###Input example:
Here is a set of inputs. For example:
```in
three
_ Happy_ New_ Year_
ywwyww
zjczzzjczjczzzjc
```
###Output example:
The corresponding output is given here. For example:
```out
seventeen
seven
thirty-two
```







answer:If there is no answer, please comment