
https://programmers.co.kr/learn/courses/30/lessons/77486
코딩테스트 연습 - 다단계 칫솔 판매
민호는 다단계 조직을 이용하여 칫솔을 판매하고 있습니다. 판매원이 칫솔을 판매하면 그 이익이 피라미드 조직을 타고 조금씩 분배되는 형태의 판매망입니다. 어느정도 판매가 이루어진 후,
programmers.co.kr
def cal_dividend(seller,amount,member_dict={}):
dividend = int(amount*0.1)
# 배당금 10% 1미만
if dividend < 1 :
member_dict[seller][1] += amount # 그대로 순이익
# 배당금 10% 1이상 and 추천인 X
elif member_dict[seller][0] =='-':
member_dict[seller][1] += amount - dividend
# 배당금 10% 1이상 and 추천인 O
else:
member_dict[seller][1] += amount - dividend
cal_dividend(member_dict[seller][0],dividend,member_dict)
def solution(enroll, referral, seller, amount):
member_dict = {}
for en,re in zip(enroll,referral):
member_dict[en]=[re,0]
amount = list(map(lambda x:x*100,amount))
for sellery,count in zip(seller,amount):
cal_dividend(sellery, count,member_dict)
answer = []
for member in enroll:
answer.append(member_dict[member][1])
return answer
풀이 방법 :
1. 판매원과 추천인을 dictonary에 추가해준다.
2. 판매량인 amount에 100을 곱해서 판매 수익으로 만들어 준다.
3. 판매원, 판매 수익, 판매 정보가 담긴 dict를 cal_dividend 함수로 넘긴다.
4. 배당금 10%가 1원 미만일 경우 그대로 순이익
5. 배당금 10%가 1원 이상일 경우
a. 추천인 X (민호) : 배당금을 제외하고 판매 수익을 저장함
b. 추천인 O :
배당금을 제외하고 판매 수익을 저장함
배당금과 추천인으로 재귀적으로 cal_dividend 함수로 넘긴다.
'Programming > Programmers' 카테고리의 다른 글
[프로그래머스] 디스크 컨트롤러(Python) (0) | 2021.08.12 |
---|---|
[프로그래머스] N으로 표현(Python) (0) | 2021.08.12 |
[프로그래머스] 입국심사(Python) (0) | 2021.08.12 |
[프로그래머스] 도둑질(Python) (0) | 2021.08.12 |
[프로그래머스] 징검다리(Python) (0) | 2021.08.12 |
댓글