SimeonTs

SUPyF2 Text-Pr.-Ex. - 10. Winning Ticket

Oct 27th, 2019
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.70 KB | None | 0 0
  1. """
  2. Text Processing - Exercise
  3. Check your code: https://judge.softuni.bg/Contests/Practice/Index/1740#9
  4.  
  5. SUPyF2 Text-Pr.-Ex. - 10. Winning Ticket (not included in final score)
  6.  
  7. Problem:
  8. Lottery is exciting. What is not, is checking a million tickets for winnings only by hand.
  9. So, you are given the task to create a program which automatically checks if a ticket is a winner.
  10. You are given a collection of tickets separated by commas and spaces.
  11. You need to check every one of them if it has a winning combination of symbols.
  12. A valid ticket should have exactly 20 characters. The winning symbols are '@', '#', '$' and '^'.
  13. But in order for a ticket to be a winner the symbol should uninterruptedly repeat for at least 6 times in both
  14. the tickets left half and the tickets right half.
  15. For example, a valid winning ticket should be something like this:
  16. "Cash$$$$$$Ca$$$$$$sh"
  17. The left half "Cash$$$$$$" contains "$$$$$$", which is also contained in the tickets right half "Ca$$$$$$sh".
  18. A winning ticket should contain symbols repeating up to 10 times in both halves, which is considered a Jackpot (for example: "$$$$$$$$$$$$$$$$$$$$").
  19. Input
  20. The input will be read from the console.
  21. The input consists of a single line containing all tickets separated by
  22. commas and one or more white spaces in the format:
  23. • "{ticket}, {ticket}, … {ticket}"
  24. Output
  25. Print the result for every ticket in the order of their appearance, each on a separate line in the format:
  26. • Invalid ticket - "invalid ticket"
  27. • No match - "ticket "{ticket}" - no match"
  28. • Match with length 6 to 9 - "ticket "{ticket}" - {match length}{match symbol}"
  29. • Match with length 10 - "ticket "{ticket}" - {match length}{match symbol} Jackpot!"
  30. Constrains
  31. • Number of tickets will be in range [0 … 100]
  32. Examples:
  33. Input:
  34. Cash$$$$$$Ca$$$$$$sh
  35. Output:
  36. ticket "Cash$$$$$$Ca$$$$$$sh" - 6$
  37.  
  38. Input:
  39. $$$$$$$$$$$$$$$$$$$$, aabb  , th@@@@@@eemo@@@@@@ey
  40. Output:
  41. ticket "$$$$$$$$$$$$$$$$$$$$" - 10$ Jackpot!
  42. invalid ticket
  43. ticket "th@@@@@@eemo@@@@@@ey" - 6@
  44.  
  45. Input:
  46. validticketnomatch:(
  47. Output:
  48. ticket "validticketnomatch:(" - no match
  49. """
  50. a = [''.join([letter for letter in item if letter != ' ']) for item in input().split(", ")]
  51. for ticket in a:
  52.     if len(ticket) == 20:
  53.         middle = (len(ticket) + 1) // 2
  54.         left_half = ticket[:middle]
  55.         right_half = ticket[middle:]
  56.  
  57.         if "@@@@@@" in left_half and "@@@@@@" in right_half:
  58.             total_times = min(left_half.count("@"), right_half.count("@"))
  59.             if total_times == 10:
  60.                 print(f'ticket "{ticket}" - 10@ Jackpot!')
  61.             else:
  62.                 print(f'ticket "{ticket}" - {total_times}@')
  63.  
  64.         elif "######" in left_half and "######" in right_half:
  65.             total_times = min(left_half.count("#"), right_half.count("#"))
  66.             if total_times == 10:
  67.                 print(f'ticket "{ticket}" - 10# Jackpot!')
  68.             else:
  69.                 print(f'ticket "{ticket}" - {total_times}#')
  70.  
  71.         elif "$$$$$$" in left_half and "$$$$$$" in right_half:
  72.             total_times = min(left_half.count("$"), right_half.count("$"))
  73.             if total_times == 10:
  74.                 print(f'ticket "{ticket}" - 10$ Jackpot!')
  75.             else:
  76.                 print(f'ticket "{ticket}" - {total_times}$')
  77.  
  78.         elif "^^^^^^" in left_half and "^^^^^^" in right_half:
  79.             total_times = min(left_half.count("^"), right_half.count("^"))
  80.             if total_times == 10:
  81.                 print(f'ticket "{ticket}" - 10^ Jackpot!')
  82.             else:
  83.                 print(f'ticket "{ticket}" - {total_times}^')
  84.  
  85.         else:
  86.             print(f'ticket "{ticket}" - no match')
  87.     else:
  88.         print(f'invalid ticket')
Add Comment
Please, Sign In to add comment