Advertisement
dimanou_04

01. Ranking

Jul 12th, 2022
43
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.67 KB | None | 0 0
  1. from collections import defaultdict
  2.  
  3. contest_and_pass = defaultdict(str)
  4. competition_data = {}
  5. valid = False
  6.  
  7. while True:
  8.     command = input()
  9.     if command == "end of contests":
  10.         break
  11.     command = command.split(':')
  12.     contest, password = command
  13.     contest_and_pass[contest] = password
  14.  
  15. while True:
  16.     command = input()
  17.     if command == "end of submissions":
  18.         break
  19.  
  20.     command = command.split('=>')
  21.     contest, password, username, points = command
  22.     if contest in contest_and_pass.keys() and password in contest_and_pass.values():
  23.         valid = True
  24.  
  25.     if valid:
  26.         if username not in competition_data:
  27.             competition_data[username] = {}
  28.             competition_data[username][contest] = int(points)
  29.         if contest not in competition_data[username]:
  30.             competition_data[username][contest] = int(points)
  31.         if int(points) > competition_data[username][contest]:
  32.             max_points = int(points)
  33.             competition_data[username][contest] = max_points
  34.     valid = False
  35.  
  36. highest_score_person = ""
  37. highest_score = 0
  38. for key, value in competition_data.items():
  39.     for name in competition_data.keys():
  40.         score_for_user = sum(value.values())
  41.         if score_for_user > highest_score:
  42.             highest_score = score_for_user
  43.             highest_score_person = name
  44.         break
  45. print(f"Best candidate is {highest_score_person} with total {highest_score} points.")
  46. print("Ranking:")
  47.  
  48. for name in sorted(competition_data.keys()):
  49.     print(name)
  50.     for contest, points in sorted(competition_data[name].items(), key=lambda item: -item[1]):
  51.         print(f"#  {contest} -> {points}")
  52.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement