TopCoder problem "StringSquares" used in TCCC06 Round 1A (Division I Level One)



Problem Statement

    We call a string a square if it is a concatenation of two equal non-empty strings. All string comparisons in this problem are case sensitive. For example, "aa", "ABAB", and "abcabc" are squares, but "a", "aaa", "ABCabc", and "abcab" are not.



Given a String s, return the number of distinct squares that appear as contiguous substrings of s. For example, in "aaabccabccCC", you can find the squares "aa", "abccabcc", "cc", and "CC", so you would return 4. The squares "aa" and "cc" each appear twice in the string, but they're only counted once because we're only interested in distinct squares.
 

Definition

    
Class:StringSquares
Method:count
Parameters:String
Returns:int
Method signature:int count(String s)
(be sure your method is public)
    
 

Constraints

-s will contain between 0 and 50 characters, inclusive.
-s will contain only letters ('a'-'z', 'A'-'Z').
 

Examples

0)
    
"aaabccabccCC"
Returns: 4
The example in the problem statement.
1)
    
"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
Returns: 21
2)
    
"cc"
Returns: 1
3)
    
"B"
Returns: 0
4)
    
"ABCDABCDabcdabcdABCDABCDabcdabcd"
Returns: 3

Problem url:

http://www.topcoder.com/stat?c=problem_statement&pm=6726

Problem stats url:

http://www.topcoder.com/tc?module=ProblemDetail&rd=10097&pm=6726

Writer:

Cosmin.ro

Testers:

PabloGilberto , brett1479 , vorthys , Olexiy

Problem categories:

Brute Force