﻿

# Untitled

Dec 3rd, 2020
575
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
1. def update_judge(user, contest, points):
2.     global judge, users
3.     user_idx = -1
4.     for idx in range(len(judge)):
5.         if judge[idx]["user"] == user and judge[idx]["contest"] == contest:
6.             user_idx = idx
7.             break
8.     if user_idx == -1:
9.         judge.append({"user": user, "contest": contest, "points": points})
10.     else:
11.         if judge[user_idx]["points"] < points:
12.             judge[user_idx]["points"] = points
13.     if contest not in contests:
14.         contests.append(contest)
15.     if user not in users:
16.         users.append(user)
17.
18.
19. def get_contest_users(contest):
20.     global judge
21.     arr = []
22.     for index in range(len(judge)):
23.         current = judge[index]
24.         if current["contest"] == contest:
25.             arr.append(current)
26.     return arr
27.
28.
29. def get_user_points(usr):
30.     global judge
31.     pts = 0
32.     for idx in range(len(judge)):
33.         if judge[idx]["user"] == usr:
34.             pts += judge[idx]["points"]
35.     return pts
36.
37.
38. def get_contests():
39.     global judge, contests
40.     arr = []
41.     for contest in contests:
42.         for idx in range(len(judge)):
43.             if judge[idx]["contest"] == contest:
44.                 i = -1
45.                 for ii in range(len(arr)):
46.                     if arr[ii]["contest"] == contest:
47.                         i = ii
48.                         break
49.                 if i == -1:
50.                     arr.append({"contest": contest, "points": judge[idx]["points"]})
51.                 else:
52.                     arr[i]["points"] += judge[idx]["points"]
53.     return arr
54.
55.
56. judge = []
57. contests = []
58. users = []
59. entry = input()
60. while entry != "no more time":
61.     user, contest, points = entry.split(" -> ")
62.     points = int(points)
63.     update_judge(user, contest, points)
64.
65.     entry = input()
66.
67. for result in get_contests():
68.     contest_results = get_contest_users(result["contest"])
69.     print(f"{result['contest']}: {len(contest_results)} participants")
70.     num = 1
71.     for contest_usr in sorted(contest_results, key=lambda x: (-x["points"], x["user"])):
72.         print(f"{num}. {contest_usr['user']} <::> {contest_usr['points']}")
73.         num += 1
74. print("Individual standings:")
75. num = 1
76.
77. # usr_results = [list({usr, get_user_points(usr)}) for usr in users]
78. usr_results = []
79. for usr in users:
80.     usr_results.append({"user": usr, "points": get_user_points(usr)})
81.
82. for usr in sorted(usr_results, key=lambda x: (-x["points"], x['user'])):
83.     print(f"{num}. {usr['user']} -> {usr['points']}")
84.     num += 1
85.
86.
RAW Paste Data