F.A.Q
Hand In Hand
Online Acmers
Problem Archive
Realtime Judge Status
Authors Ranklist
 
     C/C++/Java Exams     
ACM Steps
Go to Job
Contest LiveCast
ICPC@China
Best Coder beta
VIP | STD Contests
    DIY | Web-DIY beta
Author ID 
Password 
 Register new ID

string matching

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others)
Total Submission(s): 2462    Accepted Submission(s): 1026


Problem Description
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.
 

Input
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
 

Output
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.
 

Sample Input
3 _Happy_New_Year_ ywwyww zjczzzjczjczzzjc
 

Sample Output
17 7 32
 

Source
 

Statistic | Submit | Discuss | Note
Hangzhou Dianzi University Online Judge 3.0
Copyright © 2005-2024 HDU ACM Team. All Rights Reserved.
Designer & Developer : Wang Rongtao LinLe GaoJie GanLu
Total 0.000000(s) query 1, Server time : 2024-04-16 14:22:04, Gzip enabled