일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
Tags
- 햇소
- ChatGPT
- hooks
- 우아한테코톡
- AI
- git
- github
- learn next.js
- ES6+
- dev
- This
- ES5+
- CSS
- react
- object
- 변수
- API
- JS
- 최적화
- gitCLI
- html5
- 선택자
- array
- hatso
- es6
- JavaScript
- DOM
- Python
- next.js
- 함수
Archives
- Today
- Total
codinghatso
알고리즘 with python.06 본문
쓱 최대로 할인 적용하기
코드
버블,선택,삽입 정렬을 이해한 우리는 파이썬에서 제공하는 .sort함수를 사용할 자격이 있다.
배열을 reverse=True를 이용해 내림차순으로 정렬한다.
인덱스 값을 활용하여 할인율 적용.
shop_prices = [30000, 2000, 1500000]
user_coupons = [20, 40]
def get_max_discounted_price(prices, coupons):
shop_prices.sort(reverse=True)
print(shop_prices)
user_coupons.sort(reverse=True)
print(user_coupons)
price_index = 0
coupon_index = 0
max_discounted_price = 0
while price_index < len(prices) and coupon_index < len(coupons):
max_discounted_price += prices[price_index] * (100 - coupons[coupon_index]) / 100
price_index += 1
coupon_index += 1
while price_index < len(prices):
max_discounted_price += prices[price_index]
price_index += 1
return max_discounted_price
print(get_max_discounted_price(shop_prices, user_coupons)) # 926000 이 나와야 합니다.
'코테일지' 카테고리의 다른 글
알고리즘 with python.08 (0) | 2021.06.13 |
---|---|
알고리즘 with python.07 (0) | 2021.06.13 |
알고리즘 with python.05 (0) | 2021.05.30 |
알고리즘 with python.04 (0) | 2021.05.30 |
알고리즘 with python.03 (0) | 2021.05.30 |
Comments