Advertisement
go6odn28

2judge

Mar 27th, 2024
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.57 KB | None | 0 0
  1. def sort_and_print_result(contests, standings):
  2.     for curr_contest, participants in contests.items():
  3.         print(f"{curr_contest}: {len(participants)} participants")
  4.         sorted_contest_data = dict(sorted(participants.items(), key=lambda x: (-x[1], x[0])))
  5.         num = 1
  6.         for user, curr_points in sorted_contest_data.items():
  7.             print(f"{num}. {user} <::> {curr_points}")
  8.             num += 1
  9.  
  10.     sorted_individual_standings = dict(sorted(standings.items(), key=lambda x: (-x[1], x[0])))
  11.     num = 1
  12.     print("Individual standings:")
  13.     for curr_name, current_points in sorted_individual_standings.items():
  14.         print(f"{num}. {curr_name} -> {current_points}")
  15.         num += 1
  16.  
  17.  
  18. def judge_task():
  19.     contests_data = {}
  20.     individual_standings = {}
  21.     while True:
  22.         command = input()
  23.         if command == "no more time":
  24.             break
  25.  
  26.         data = command.split(" -> ")
  27.         name, contest, points = data[0], data[1], int(data[2])
  28.  
  29.         if contest not in contests_data:
  30.             contests_data[contest] = {}
  31.  
  32.         if name not in contests_data[contest]:
  33.             contests_data[contest][name] = points
  34.             if name not in individual_standings:
  35.                 individual_standings[name] = 0
  36.             individual_standings[name] += points
  37.  
  38.         else:
  39.             if contests_data[contest][name] < points:
  40.                 contests_data[contest][name] = points
  41.                 individual_standings[name] = points
  42.  
  43.     sort_and_print_result(contests_data, individual_standings)
  44.  
  45.  
  46. judge_task()
  47.  
  48.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement