Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import sys
- userInput = []
- # kicks off recursion
- def calculate (x):
- return result (x, x)
- # a - suffix, b - original word
- def result (a, b):
- if len(a) == 0:
- return 0
- else:
- return calculatedResult (a, b, 0) + result (a[1:], b)
- def calculatedResult (c, d, loc):
- if loc == len (c):
- return 0
- if (c[loc] == d[loc]):
- return 1 + calculatedResult (c, d, loc + 1)
- else:
- return 0
- # Parse each line of STDIN
- numStrings = raw_input()
- for t in range (0, int(numStrings)):
- userInput.append(raw_input())
- # first number specifies number of strings
- numStrings = userInput[0]
- for s in userInput:
- fin = calculate (s)
- print(fin)
Add Comment
Please, Sign In to add comment