Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Alonso Vidales
committed
Mar 21, 2013
1 parent
4dd0e2b
commit 9954cd4
Showing
5 changed files
with
36 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
Unique substrings | ||
================= | ||
|
||
Given a string, find the number of unique substrings in it. The string will contain a maximum of 1000 characters and each character will be in the range 'a' - 'z' or 'A' - 'Z'. A substring is a contiguous set of characters. | ||
|
||
Sample input | ||
abababababababababababababababababab | ||
|
||
Sample output | ||
71 | ||
|
||
Read the string from STDIN and output to STDOUT |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
abababababababababababababababababab |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
71 |
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
#!/usr/bin/env python | ||
|
||
__author__ = "Alonso Vidales" | ||
__email__ = "alonso.vidales@tras2.es" | ||
__date__ = "2013-03-21" | ||
|
||
class UniqueSubstrings: | ||
def resolve(self): | ||
# Will contain all the possible substrings | ||
substrings = set() | ||
|
||
# Get all the possible substrings from the main string | ||
for count in xrange(0, len(self.string)): | ||
for subStrLen in xrange(0, len(self.string) - count): | ||
substrings.add(self.string[count:count + subStrLen + 1]) | ||
|
||
return len(substrings) | ||
|
||
def __init__(self, inStr): | ||
self.string = inStr | ||
|
||
print UniqueSubstrings(raw_input()).resolve() |