Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- contests = {}
- data = input()
- while not data == 'end of contests':
- contest, password = data.split(":")
- if contest not in contests:
- contests[contest] = password
- data = input()
- username_dict = {}
- data = input()
- while not data == 'end of submissions':
- contest, password, username, points = data.split("=>")
- points = int(points)
- is_valid = False
- if contest in contests:
- if contests[contest] == password:
- is_valid = True
- if is_valid:
- if username not in username_dict:
- username_dict[username] = {}
- username_dict[username][contest] = points
- else:
- if contest in username_dict[username]:
- if username_dict[username][contest] < points:
- username_dict[username][contest] = points
- else:
- username_dict[username][contest] = points
- data = input()
- max_points = 0
- max_name = ''
- for name, value in username_dict.items():
- sum_points = 0
- for key in value:
- sum_points += value[key]
- if sum_points > max_points:
- max_points = sum_points
- max_name = name
- print(f"Best candidate is {max_name} with total {max_points} points.")
- sorted_dict = dict(sorted(username_dict.items(), key=lambda x: x[0]))
- # SORT NESTED DICT BY VALUE
- print("Ranking:")
- for name, value in sorted_dict.items():
- print(f"{name}")
- sorted_items = dict(sorted(value.items(), key=lambda x: (-x[1], x[0])))
- for k2, v2 in sorted_items.items():
- print(f'# {k2} -> {v2}')
Advertisement
Add Comment
Please, Sign In to add comment