Created
September 24, 2012 20:01
-
-
Save gregorym/3778010 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
# Enter your code here. Read input from STDIN. Print output to STDOUT | |
N = gets.to_i | |
words = [] | |
while words.length < N do | |
words << gets.sub(/\\n$/, '').strip | |
end | |
words.each do |word| | |
count = 0 | |
(word.length).times do |i| | |
sub = word[i..-1] | |
j=0 | |
while j < sub.length && sub[j] == word[j] do | |
count += 1 | |
j+=1 | |
end | |
end | |
puts count | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment