-
Notifications
You must be signed in to change notification settings - Fork 0
/
facetook_priority_wall.py
49 lines (42 loc) · 1.54 KB
/
facetook_priority_wall.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
'''
Problem Link https://codeforces.com/contest/75/problem/B
'''
import re
my_name = input()
num_of_interactions = int(input())
post = re.compile(r"(\w+) posted on (\w+)'s wall")
comment = re.compile(r"(\w+) commented on (\w+)'s post")
like = re.compile(r"(\w+) likes (\w+)'s post")
friends = dict()
def get_other_name(my_name, groups):
global firends
other_name = str()
if (groups[0] == my_name):
other_name = groups[1]
elif(groups[1] == my_name):
other_name = groups[0]
else:
friends[groups[0]] = friends.get(groups[0], 0)
friends[groups[1]] = friends.get(groups[1], 0)
return other_name
for _ in range(num_of_interactions):
line = input()
post_result = post.match(line)
comment_result = comment.match(line)
like_result = like.match(line)
if (post_result):
#print("post matched")
other_name = get_other_name(my_name, post_result.groups())
if (other_name):
friends[other_name] = friends.get(other_name, 0) + 15
elif(comment_result):
#print("comment matched")
other_name = get_other_name(my_name, comment_result.groups())
if (other_name):
friends[other_name] = friends.get(other_name, 0) + 10
elif(like_result):
#print("like matched")
other_name = get_other_name(my_name, like_result.groups())
if (other_name):
friends[other_name] = friends.get(other_name, 0) + 5
print(*[name for name, priority in sorted(friends.items(), key=lambda item: (-item[1], item))], sep='\n')