Advertisement
makispaiktis

Exetastiki2020 - Code 1 - Quality

Jul 13th, 2020 (edited)
1,018
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.03 KB | None | 0 0
  1. from quality import quality
  2.  
  3. # Question 17
  4. print(quality("one easy way to con serve water"))
  5.  
  6. # Questions 18, 19 and 20
  7. def split(text):
  8.     # Data
  9.     n = len(text)
  10.     q = [0 for _ in range(n+1)]
  11.     q[0] = 0# αρχική τιμή του αναδρομικού τύπου
  12.  
  13.     # For-loops
  14.     for i in range(1, n+1):
  15.         maxI = -float('inf')
  16.         for j in range(0, i):
  17.             value = q[j] + quality(text[j:i])
  18.             if value > maxI:
  19.                 maxI = value
  20.         q[i] = maxI
  21.  
  22.  
  23.     return q[n]
  24.  
  25. # MAIN FUNCTION
  26. text = "the574thbombardmentsquadronisaninactiveunitedstatesairforceunitthesquadronwasaworldwariiunitassignedtothe391stbombardmentgroupaftertrainingintheunitedstatesthesquadronmovedtoenglandandparticipatedinoperationsagainstgermanyfromthereandtheeuropeancontinentaspartofixbombercommanditearnedadistinguishedunitcitationforitscombatactionsfollowingv-edaythesquadronreturnedtotheunitedstatesandwasinactivatedattheportofembarkation"
  27. print(split(text))
  28. # print(quality(text)) ----> -420000
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement