Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from quality import quality
- # Question 17
- # print(quality("one easy way to con serve water"))
- # Questions 18, 19 and 20
- def split(text):
- # Data
- n = len(text)
- q = [0 for _ in range(n+1)]
- split_points = [None for _ in range(n+1)]
- q[0] = 0# αρχική τιμή του αναδρομικού τύπου
- split_points[0] = None
- # For-loops
- for i in range(1, n+1):
- maxI = -float('inf')
- split_point = None
- for j in range(0, i):
- value = q[j] + quality(text[j:i])
- if value > maxI:
- maxI = value
- split_point = j
- q[i] = maxI
- split_points[i] = split_point
- return q[n], split_points
- # Function 2
- def split2str(text, split_points, i):
- j = split_points[i]# συμπληρώστε
- if j==0:
- return text[0:i]
- word = text[j:i]
- return split2str(text, split_points, i-1)+" "+word # συμπληρώστε το ???
- # MAIN FUNCTION
- text = "lee'ssummitisanamtraktrainstationinlee'ssummitmissouriunitedstatesthestationwasoriginallybuiltin1905bythemissouripacificrailroadalthoughthestationhouseremainsintactpassengerboardthetrainsfromanall-glassrailhouseacrossthetracks"
- qual, split_points = split(text)
- print(qual)
- print(split2str(text, split_points, len(text)-1))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement