jumboframe

Untitled

Dec 2nd, 2020
706
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2. import sys
  3. best_user = ""
  4. best_points = -sys.maxsize
  5.  
  6.  
  7. def find_user_points(user):
  8.     global submissions, users
  9.     user_subs = []
  10.     if user not in users:
  11.         return user_subs
  12.     for idx in range(len(submissions)):
  13.         current = submissions[idx]
  14.         if current["username"] == user:
  15.             user_subs.append( current["points"])
  16.     return user_subs
  17.  
  18.  
  19. def find_best_user():
  20.     global users, best_points, best_user
  21.     for usr in users:
  22.         candidate = sum(find_user_points(usr))
  23.         if candidate > best_points:
  24.             best_user = usr
  25.             best_points = candidate
  26.  
  27.  
  28. def find_user_submissions(usr):
  29.     global users, submissions
  30.     usr_submissions = []
  31.     if usr not in users:
  32.         return usr_submissions
  33.     for idx in range(len(submissions)):
  34.         current = submissions[idx]
  35.         if current["username"] == usr:
  36.             usr_submissions.append(current)
  37.     return usr_submissions
  38.  
  39.  
  40. contests = {}
  41. submissions = []
  42. users = []
  43. found = False
  44. entry = input()
  45. while entry != "end of contests":
  46.     contest, password = entry.split(":")
  47.     if contest not in contests:
  48.         contests[contest] = password
  49.     entry = input()
  50.  
  51. entry = input()
  52. while entry != "end of submissions":
  53.     contest, password, username, points = entry.split("=>")
  54.     points = int(points)
  55.     if contest not in contests or contests[contest] != password:
  56.         entry = input()
  57.         continue
  58.     index = 0
  59.     while index < len(submissions):
  60.         current_submission = submissions[index]
  61.         if current_submission["username"] == username and current_submission["contest"] == contest:
  62.             found = True
  63.             if current_submission["points"] < points:
  64.                 submissions[index]["points"] = points
  65.         index += 1
  66.     if not found:
  67.         submissions.append({"username": username, "contest": contest, "points": points})
  68.         if username not in users:
  69.             users.append(username)
  70.     found = False
  71.     entry = input()
  72. find_best_user()
  73.  
  74. print(f"Best candidate is {best_user} with total {best_points} points.\nRanking:")
  75. for usr in sorted(users):
  76.     usr_subs = find_user_submissions(usr)
  77.     print(f"{usr}")
  78.     for contest in sorted(usr_subs, key=lambda x: x["points"], reverse=True):
  79.         print(f"#  {contest['contest']} -> {contest['points']}")
  80. # print(submissions)
  81.  
RAW Paste Data