SimeonTs

SUPyF Exam Preparation 1 - 03. Football League

Aug 16th, 2019
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.82 KB | None | 0 0
  1. """
  2. Basics OOP Principles
  3. Check your solution: https://judge.softuni.bg/Contests/Practice/Index/967#2
  4.  
  5. SUPyF Exam Preparation 1 - 03. Football League
  6.  
  7. Problem:
  8. You will be given information about results of football matches. Create a standings table by points.
  9. For win the team gets 3 points, for loss – 0 and for draw – 1.
  10. Also find the top 3 teams with most scored goals in descending order.
  11. If two or more teams are with same goals scored or same points order them by name in ascending order.
  12. The name of each team is encrypted. You must decrypt it before proceeding with calculating statistics.
  13. You will be given some string key and the team name will be placed between that key in reversed order.
  14. For example: the key: “???”;
  15. String to decrypt: “kfle???airagluB???gertIt%%” -> “airagluB” -> “Bulgaria”
  16. Also you should ignore the letter casing in the team names. For example:
  17. buLgariA = BulGAria = bulGARIA = BULGARIA
  18. Input / Constraints
  19. • On the first line of input you will get the key that will be used for decryption
  20. • On the next lines until you receive “final” you will get lines in format:
  21. {encrypted teamA} {encrypted teamB} {teamA score}:{teamB score}
  22. • Team scores will be integer numbers in the range [0...231]
  23. Output
  24. • Print the standings table ordered descending by points in format:
  25. Where place is a number in range [1… number of teams].
  26. • Then you should print the top 3 team ordered by goals in descending order in format:
  27. • All team’s names should be uppercase.
  28. • For more clarification, see the examples on the next page.
  29.  
  30. Examples:
  31. Input:
  32. ??
  33. ??ecnarF?? ??kramneD?? 0:0
  34. ..??airagluB??32 ??dnalgnE??gf 3:2
  35. Fg??NIAPS?? fgdrt%#$??YNAMREG??gtr 3:4
  36. ??eCnArF?? >>??yLATi??<< 2:2
  37. final
  38.  
  39. Output:
  40. League standings:
  41. 1. BULGARIA 3
  42. 2. GERMANY 3
  43. 3. FRANCE 2
  44. 4. DENMARK 1
  45. 5. ITALY 1
  46. 6. ENGLAND 0
  47. 7. SPAIN 0
  48. Top 3 scored goals:
  49. - GERMANY -> 4
  50. - BULGARIA -> 3
  51. - SPAIN -> 3
  52.  
  53. Input:
  54. KZL
  55. fdKZLairagluBKZL KZLkramneDKZLll 2:0
  56. kzljjjKZLAiRaGluBKZL KZLylATIKZLkk 1:1
  57. KZLkRamnedKZL KZLYlatiKZL 4:4
  58. final
  59.  
  60. Output:
  61. League standings:
  62. 1. BULGARIA 4
  63. 2. ITALY 2
  64. 3. DENMARK 1
  65. Top 3 scored goals:
  66. - ITALY -> 5
  67. - DENMARK -> 4
  68. - BULGARIA -> 3
  69. """
  70.  
  71. teams = {}
  72.  
  73. key = input()
  74. while True:
  75.     command = input()
  76.     if command == "final":
  77.         break
  78.     team_1_encrypted, team_2_encrypted, result = command.split()
  79.     goals_team_1, goals_team_2 = (int(item) for item in result.split(":"))
  80.     team1 = ((team_1_encrypted.split(key))[1].split(key)[0])[::-1].upper()
  81.     team2 = ((team_2_encrypted.split(key))[1].split(key)[0])[::-1].upper()
  82.     team1_score_points = 0
  83.     team2_score_points = 0
  84.     if goals_team_1 == goals_team_2:
  85.         team1_score_points = 1
  86.         team2_score_points = 1
  87.     elif goals_team_1 > goals_team_2:
  88.         team1_score_points = 3
  89.     elif goals_team_2 > goals_team_1:
  90.         team2_score_points = 3
  91.  
  92.     if team1 not in teams:
  93.         teams[team1] = []
  94.         teams[team1] += [team1_score_points, goals_team_1]
  95.     else:
  96.         a = teams[team1]
  97.         a[0] += team1_score_points
  98.         a[1] += goals_team_1
  99.         teams[team1] = a
  100.     if team2 not in teams.keys():
  101.         teams[team2] = []
  102.         teams[team2] += [team2_score_points, goals_team_2]
  103.     else:
  104.         a = teams[team2]
  105.         a[0] += team2_score_points
  106.         a[1] += goals_team_2
  107.         teams[team2] = a
  108.  
  109. place = 1
  110. print("League standings:")
  111. for key, value in sorted(sorted(teams.items(), key=lambda kv: kv[0]), key=lambda key_: key_[1][0], reverse=True):
  112.     print(f"{place}. {key} {value[0]}")
  113.     place += 1
  114.  
  115. counter = 0
  116.  
  117. print("Top 3 scored goals:")
  118. for key, value in sorted(sorted(teams.items(), key=lambda kv: kv[0]), key=lambda key_: key_[1][1], reverse=True):
  119.     print(f"- {key} -> {value[1]}")
  120.     counter += 1
  121.     if counter == 3:
  122.         break
Add Comment
Please, Sign In to add comment