Skip to content

Commit

Permalink
29.py
Browse files Browse the repository at this point in the history
  • Loading branch information
huisuu committed Aug 19, 2024
1 parent 1ae1c61 commit 92fc5b1
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions HSKIM/21to30/29.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
def solution(enroll, referral, seller, amount):
parent = dict(zip(enroll, referral))

total = {name: 0 for name in enroll}

for i in range(len(seller)):
money = amount[i] * 100
cur_name = seller[i]

while money > 0 and cur_name != "-":
total[cur_name] += money - money // 10
cur_name = parent[cur_name]

money //= 10

return [total[name] for name in enroll]


# enroll = ['john', 'mary', 'edward', 'sam' , 'emily' , 'jaimie' ,'tod', 'young']
# referral = ['-', '-', 'mary', 'edward', 'mary', 'mary', 'jaimie', 'edward']
# seller = ['young', 'john', 'tod', 'emily', 'mary']
# amount = [12, 4, 2, 5, 10]
# print(solution(enroll, referral, seller, amount))

0 comments on commit 92fc5b1

Please sign in to comment.