Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
Tags
- MySQL
- 자료구조 및 실습
- 딥러닝
- C++
- cs
- 모두를 위한 딥러닝 강좌 시즌1
- 구현
- 이것이 코딩테스트다 with 파이썬
- 코드수행
- 백준
- SWEA
- 프로그래머스
- 전산기초
- 1단계
- CS231n
- 그리디
- ssd
- Object detection
- 파이썬
- 실전알고리즘
- 2단계
- STL
- AWS
- docker
- pytorch
- ubuntu
- test-helper
- 3단계
- Python
- 머신러닝
Archives
- Today
- Total
곰퓨타의 SW 이야기
[프로그래머스 level3 다단계 칫솔 판매] 딕셔너리 활용하기 본문
해결해야하는 문제는 다음과 같았다.
https://programmers.co.kr/learn/courses/30/lessons/77486
코딩테스트 연습 - 다단계 칫솔 판매
민호는 다단계 조직을 이용하여 칫솔을 판매하고 있습니다. 판매원이 칫솔을 판매하면 그 이익이 피라미드 조직을 타고 조금씩 분배되는 형태의 판매망입니다. 어느정도 판매가 이루어진 후,
programmers.co.kr
이러한 아이디어를 바탕으로 작성한 코드는 다음과 같다.
def solution(enroll, referral, seller, amount):
answer = []
dicts = {}
tree_dicts = {}
for i in range(len(enroll)):
tree_dicts[enroll[i]] = referral[i]
dicts[enroll[i]] = 0
for i in range(len(seller)) :
cost = amount[i]*100
node = seller[i]
while node != '-':
parent = tree_dicts[node]
if cost*0.1 < 1:
dicts[node] += cost
break
dicts[node] += (cost-(cost//10))
cost //= 10
node = parent
for name in enroll :
answer.append(int(dicts[name]))
return answer
'TIL > 프로그래머스' 카테고리의 다른 글
[프로그래머스 level3 등굣길] dp 뿌시기! (0) | 2021.06.25 |
---|---|
[프로그래머스 level3 이중우선순위큐] heapq 활용하기 (0) | 2021.06.25 |
[프로그래머스 level3 셔틀버스] 시간을 '분' 단위로 처리하기 (0) | 2021.06.22 |
[프로그래머스 level3 디스크 컨트롤러] heapq 사용하기! (0) | 2021.06.18 |
[프로그래머스 level3 순위] 플로이드 워셜 알고리즘 활용하기! (0) | 2021.06.17 |
Comments