0
For two string A and B, we define the similarity of these strings is the length of the prefix that is common to both. For example, the similarity 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 its suffixes, including its own string as the first suffix.
Input Format:
The first line contains the number of test cases T. Each of the T lines next to it contains a string each.
Output Format:
Display T output lines, each containing an integer number that is for the corresponding test case.
Premises:
- 1 <= T <= 10
- As strings contains only lowercase characters [a-z]
Input example:
2
ababaa
aa
Output example:
11
3
Explanation:
For the first case, the suffixes of string sane ababaa
, babaa
, abaa
, baa
, aa
and a
. The similarities of each of these string with the string ababaa
are 6, 0, 3, 0, 1, 1 respectively. So the answer is 6 + 0 + 3 + 0 + 1 + 1 = 11. For the second case the answer is 2 + 1 = 3
Doubts
In the result of the comparison:
6 + 0 + 3 + 0 + 1 + 1 = 11
Where does 0 come from? How is the comparison made?
For now, I have only the signature of the method, which would look this way:
public static Integer semelhancaString(Integer n, String... strings) {}
Good. The site is for code correction and code analysis. It tries to create a code that we analyze it. But when comparing occurs with the string "aa" an error occurs. Pois
– Victor Henrique