Guest User

Untitled

a guest
Apr 26th, 2018
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.74 KB | None | 0 0
  1. import sys
  2. userInput = []
  3.  
  4. # kicks off recursion
  5. def calculate (x):
  6.     return result (x, x)
  7.    
  8. # a - suffix, b - original word
  9. def result (a, b):
  10.         if len(a) == 0:
  11.             return 0
  12.         else:
  13.             return calculatedResult (a, b, 0) + result (a[1:], b)
  14.  
  15. def calculatedResult (c, d, loc):
  16.     if loc == len (c):
  17.         return 0
  18.     if (c[loc] == d[loc]):
  19.         return 1 + calculatedResult (c, d, loc + 1)
  20.     else:
  21.         return 0
  22.    
  23. # Parse each line of STDIN
  24. numStrings = raw_input()
  25.  
  26. for t in range (0, int(numStrings)):
  27.     userInput.append(raw_input())
  28.  
  29.  # first number specifies number of strings  
  30. numStrings = userInput[0]
  31.  
  32. for s in userInput:
  33.     fin = calculate (s)
  34.     print(fin)
Add Comment
Please, Sign In to add comment