您好,欢迎来到99网。
搜索
您的当前位置:首页python文本分析

python文本分析

来源:99网
python⽂本分析

For two strings A and B, we define the similarity of the strings to be the length of the longest prefix common to both strings. For example, thesimilarity of strings \"abc\" and \"abd\" is 2, while the similarity of strings \"aaa\" and \"aaab\" is 3.Calculate the sum of similarities of a string S with each of it's suffixes.Input Format

The first line contains the number of test cases T. Each of the next T lines contains a string each.Constraints

1 <= T <= 10

The length of each string is at most 100000 and contains only lower case characters.Output Format

Output T lines containing the answer for the corresponding test case.Sample Input

2

ababaa aa

Sample Output

11 3

Explanation

For the first case, the suffixes of the string are \"ababaa\\"ababaa\" are 6,0,3,0,1, & 1 respectively. Thus, the answer is 6 + 0 + 3 + 0 + 1 + 1 = 11.For the second case, the answer is 2 + 1 = 3.问题如上:

如果是简单的形式来获取the sum of similarities并不是太复杂,但是当这个词巨长的时候问题就产⽣了,看了下测试数据直接上94773个t,总数溢出,程序完蛋

待解决的问题。。。。。。。。。。。。。。。。。。。。。。。。。。。。

因篇幅问题不能全部显示,请点此查看更多更全内容

Copyright © 2019- 99spj.com 版权所有 湘ICP备2022005869号-5

违法及侵权请联系:TEL:199 18 7713 E-MAIL:2724546146@qq.com

本站由北京市万商天勤律师事务所王兴未律师提供法律服务