Arksiana

1.Ranking

Dec 2nd, 2020
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.54 KB | None | 0 0
  1. contests = {}
  2.  
  3. data = input()
  4. while not data == 'end of contests':
  5.     contest, password = data.split(":")
  6.  
  7.     if contest not in contests:
  8.         contests[contest] = password
  9.     data = input()
  10.  
  11. username_dict = {}
  12.  
  13. data = input()
  14. while not data == 'end of submissions':
  15.     contest, password, username, points = data.split("=>")
  16.     points = int(points)
  17.     is_valid = False
  18.     if contest in contests:
  19.         if contests[contest] == password:
  20.             is_valid = True
  21.  
  22.     if is_valid:
  23.  
  24.         if username not in username_dict:
  25.             username_dict[username] = {}
  26.             username_dict[username][contest] = points
  27.         else:
  28.             if contest in username_dict[username]:
  29.                 if username_dict[username][contest] < points:
  30.                     username_dict[username][contest] = points
  31.             else:
  32.                 username_dict[username][contest] = points
  33.  
  34.     data = input()
  35.  
  36. max_points = 0
  37. max_name = ''
  38. for name, value in username_dict.items():
  39.     sum_points = 0
  40.     for key in value:
  41.         sum_points += value[key]
  42.     if sum_points > max_points:
  43.         max_points = sum_points
  44.         max_name = name
  45.  
  46. print(f"Best candidate is {max_name} with total {max_points} points.")
  47. sorted_dict = dict(sorted(username_dict.items(), key=lambda x: x[0]))
  48. print("Ranking:")
  49. for name, value in sorted_dict.items():
  50.     print(f"{name}")
  51.  
  52.     sorted_items = dict(sorted(value.items(), key=lambda x: (-x[1], x[0])))
  53.     for k2, v2 in sorted_items.items():
  54.         print(f'#  {k2} -> {v2}')
  55.  
Advertisement
Add Comment
Please, Sign In to add comment