File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 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
You can’t perform that action at this time.
0 commit comments