Skip to content

Commit 5baa153

Browse files
committed
pg - 258712
1 parent ad40ec0 commit 5baa153

1 file changed

Lines changed: 52 additions & 0 deletions

File tree

python/implement/pg_258712

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
# https://school.programmers.co.kr/learn/courses/30/lessons/258712
2+
# 가장 많이 받은 선물
3+
4+
def solution(friends, gifts):
5+
6+
dic = {}
7+
presentDic = {}
8+
9+
for friend in friends:
10+
dic[friend] = {}
11+
presentDic[friend] = 0
12+
13+
for gift in gifts:
14+
splitGift = gift.split()
15+
16+
a = splitGift[0]
17+
b = splitGift[1]
18+
19+
if b in dic[a]:
20+
dic[a][b] += 1
21+
else:
22+
dic[a][b] = 1
23+
24+
presentDic[a] += 1
25+
presentDic[b] -= 1
26+
27+
result = [0] * len(friends)
28+
for i in range(len(friends)):
29+
for j in range(i+1, len(friends)):
30+
a = friends[i]
31+
b = friends[j]
32+
first = 0
33+
second = 0
34+
35+
if b in dic[a]:
36+
first += dic[a][b]
37+
38+
if a in dic[b]:
39+
second += dic[b][a]
40+
41+
if first > second:
42+
result[i] += 1
43+
elif first < second:
44+
result[j] += 1
45+
elif first == second:
46+
if presentDic[a] > presentDic[b]:
47+
result[i] += 1
48+
elif presentDic[a] < presentDic[b]:
49+
result[j] += 1
50+
51+
answer = max(result)
52+
return answer

0 commit comments

Comments
 (0)