Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # SoftUni Exam Results
- # Judge statistics on the last Programing Fundamentals exam was not working correctly, so you have the task to take
- # all the submissions and analyze them properly. You should collect all the submissions and print the final results
- # and statistics about each language that the participants submitted their solutions in.
- # You will be receiving lines in the following format:
- # "{username}-{language}-{points}"
- # until you receive "exam finished". You should store each username and his submissions and points.
- # You can receive a command to ban a user for cheating in the following format:
- # "{username}-banned".
- # In that case, you should remove the user from the contest, but preserve his
- # submissions in the total count of submissions for each language.
- # After receiving "exam finished" print each of the participants, ordered descending by their max points,
- # then by username, in the following format:
- # Results:
- # {username} | {points}
- # …
- # After that print each language, used in the exam, ordered descending by total submission count and then by
- # language name, in the following format:
- # Submissions:
- # {language} – {submissionsCount}
- # …
- # Input / Constraints
- # Until you receive "exam finished" you will be receiving participant submissions in the following format:
- # "{username}-{language}-{points}".
- # You can receive a ban command -> "{username}-banned"
- # The points of the participant will always be a valid integer in the range [0-100];
- # Output
- # • Print the exam results for each participant, ordered descending by max points and then by username, in
- # the following format:
- # Results:
- # {username} | {points}
- # …
- # • After that print each language, ordered descending by total submissions and then by language name, in
- # the following format:
- # Submissions:
- # {language} – {submissionsCount}
- # …
- # • Allowed working time / memory: 100ms / 16MB.
- def ban_user(del_user):
- global judge
- if del_user in judge:
- del(judge[del_user])
- def check_record(lang, usr, pt):
- global judge, submission_count
- if usr not in judge:
- judge[usr] = pt
- elif pt > judge[usr]:
- judge[usr] = pt
- if lang not in submission_count:
- submission_count[lang] = 1
- else:
- submission_count[lang] += 1
- judge = {}
- submission_count = {}
- entry = input()
- while entry != "exam finished":
- if entry.split("-")[1] == "banned":
- ban_user(entry.split("-")[0])
- entry = input()
- continue
- username, language, points = entry.split("-")
- points = int(points)
- check_record(language, username, points)
- entry = input()
- print("Results:")
- for student in sorted(judge.items(), key=lambda x: (-x[1], x[0])):
- print(f"{student[0]} | {student[1]}")
- print("Submissions:")
- for lang in sorted(submission_count, key=lambda x: (x, -submission_count[x])):
- print(f"{lang} - {submission_count[lang]}")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement