jumboframe

Untitled

Mar 23rd, 2021
707
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. # SoftUni Exam Results
  2. # Judge statistics on the last Programing Fundamentals exam was not working correctly, so you have the task to take
  3. # all the submissions and analyze them properly. You should collect all the submissions and print the final results
  4. # and statistics about each language that the participants submitted their solutions in.
  5. # You will be receiving lines in the following format:
  6. #       "{username}-{language}-{points}"
  7. #       until you receive "exam finished". You should store each username and his submissions and points.
  8. # You can receive a command to ban a user for cheating in the following format:
  9. #       "{username}-banned".
  10. #       In that case, you should remove the user from the contest, but preserve his
  11. #       submissions in the total count of submissions for each language.
  12. # After receiving "exam finished" print each of the participants, ordered descending by their max points,
  13. # then by username, in the following format:
  14. # Results:
  15. #       {username} | {points}
  16. # …
  17. # After that print each language, used in the exam, ordered descending by total submission count and then by
  18. # language name, in the following format:
  19. # Submissions:
  20. #       {language} – {submissionsCount}
  21. # …
  22. # Input / Constraints
  23. # Until you receive "exam finished" you will be receiving participant submissions in the following format:
  24. #       "{username}-{language}-{points}".
  25. # You can receive a ban command -> "{username}-banned"
  26. # The points of the participant will always be a valid integer in the range [0-100];
  27. # Output
  28. # •   Print the exam results for each participant, ordered descending by max points and then by username, in
  29. # the following format:
  30. # Results:
  31. # {username} | {points}
  32. # …
  33. # •   After that print each language, ordered descending by total submissions and then by language name, in
  34. # the following format:
  35. # Submissions:
  36. # {language} – {submissionsCount}
  37. # …
  38. #   • Allowed working time / memory: 100ms / 16MB.
  39.  
  40. def ban_user(del_user):
  41.     global judge
  42.     if del_user in judge:
  43.         del(judge[del_user])
  44.  
  45.  
  46. def check_record(lang, usr, pt):
  47.     global judge, submission_count
  48.     if usr not in judge:
  49.         judge[usr] = pt
  50.     elif pt > judge[usr]:
  51.         judge[usr] = pt
  52.  
  53.     if lang not in submission_count:
  54.         submission_count[lang] = 1
  55.     else:
  56.         submission_count[lang] += 1
  57.  
  58.  
  59. judge = {}
  60. submission_count = {}
  61. entry = input()
  62. while entry != "exam finished":
  63.     if entry.split("-")[1] == "banned":
  64.         ban_user(entry.split("-")[0])
  65.         entry = input()
  66.         continue
  67.     username, language, points = entry.split("-")
  68.     points = int(points)
  69.     check_record(language, username, points)
  70.  
  71.     entry = input()
  72.  
  73. print("Results:")
  74. for student in sorted(judge.items(), key=lambda x: (-x[1], x[0])):
  75.     print(f"{student[0]} | {student[1]}")
  76.  
  77.  
  78. print("Submissions:")
  79. for lang in sorted(submission_count, key=lambda x: (x, -submission_count[x])):
  80.     print(f"{lang} - {submission_count[lang]}")
RAW Paste Data