simeonshopov

Ranking

Feb 6th, 2020
594
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.65 KB | None | 0 0
  1. contests = {}
  2.  
  3. def check_contest(name, pasw):
  4.     if name in contests:
  5.         return contests[name] == pasw
  6.  
  7.  
  8. def manage_student(sts: dict, std: str, con: str, pts: int):
  9.     if std not in sts:
  10.         sts[std] = {con: pts}
  11.     elif std in sts:
  12.         if con not in sts[std]:
  13.             sts[std].update({con: pts})
  14.         else:
  15.             if pts > sts[std][con]:
  16.                 sts[std][con] = pts
  17.  
  18. while True:
  19.     data = input()
  20.     if data == 'end of contests':
  21.         break
  22.     data = data.split(':')
  23.     if len(data) >= 2:
  24.         contest = data[0]
  25.         password = data[1]
  26.         contests[contest] = password
  27.  
  28.  
  29. students = {}
  30. while True:
  31.     stuff = input()
  32.     if stuff == 'end of submissions':
  33.         break
  34.     stuff = stuff.split('=>')
  35.     contest_part = stuff[0]
  36.     password_try = stuff[1]
  37.     student = stuff[2]
  38.     points = int(stuff[3])
  39.     if check_contest(contest_part, password_try):
  40.         manage_student(students, student, contest_part, points)
  41.  
  42. students_points = {}
  43. for x, y in students.items():
  44.     point = sum(y.values())
  45.     students_points.update({x: point})
  46.  
  47. winner = ''.join([x for (x, y) in students_points.items() if y == max(students_points.values())])
  48.  
  49. order = sorted(students, key=lambda i: i)
  50.  
  51. print(f'Best candidate is {winner} with total {students_points[winner]} points.')
  52. print('Ranking: ')
  53. for k in order:
  54.     print(f'{k}')
  55.     # con_order = sorted(students[k], key=lambda g: students[k][g], reverse=True)
  56.     # [print(f'#  {t} -> {students[k][t]}') for t in con_order]
  57.     [print(f'#  {t} -> {students[k][t]}') for t in sorted(students[k], key=lambda g: students[k][g], reverse=True)]
Advertisement
Add Comment
Please, Sign In to add comment