Skip to content

Commit

Permalink
#28 23.09.26 > 5문제
Browse files Browse the repository at this point in the history
  • Loading branch information
beurmuz committed Sep 26, 2023
1 parent f695f2d commit b344441
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 0 deletions.
61 changes: 61 additions & 0 deletions src/programmers/Lv_0/230926.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
# ---------- 1. 순서쌍의 개수 | O
# 내 풀이
def solution(n):
answer = 0
for i in range(1, n + 1):
share, rest = divmod(n, i)
if rest == 0:
answer += 1
return answer


# 다른 풀이
def solution(n):
answer = 0
for i in range(1, n + 1):
if n % i == 0:
answer += 1
return answer


# ---------- 2. 배열 두배 만들기 | O
def solution(numbers):
return [i * 2 for i in numbers]


# ---------- 3. 문자열 안에 문자열 | O
def solution(str1, str2):
return 1 if str2 in str1 else 2


# ---------- 4. 중앙값 구하기 | O
# 내 풀이
def solution(array):
array.sort()
return array[len(array) // 2]


# 다른 풀이
def solution(array):
return sorted(array)[len(array) // 2]


# ---------- 5. 옷가게 할인 | O
# 내 풀이
def solution(price):
if price >= 500000:
return int(price * 0.8)
elif price >= 300000 and price < 500000:
return int(price * 0.9)
elif price >= 100000 and price < 300000:
return int(price * 0.95)
else:
return int(price)


# 다른 풀이
def solution(price):
discount_rates = {500000: 0.8, 300000: 0.9, 100000: 0.95, 0: 1}
for discount_price, discount_rate in discount_rates.items():
if price >= discount_price:
return int(price * discount_rate)
1 change: 1 addition & 0 deletions src/programmers/Lv_0/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@
| 5 | 배열 자르기<br>배열 뒤집기<br>점의 위치 구하기<br>중복된 숫자 개수<br>아이스 아메리카노 | [23.09.23](./230923.py) |
| 6 | 문자열 뒤집기<br>배열의 유사도<br>삼각형의 완성 조건(1)<br>자릿수 더하기<br>최댓값 만들기 (1) | [23.09.24](./230924.py) |
| 7 | 머쓱이보다 키 큰 사람<br>문자 반복 출력하기<br>특정 문자 제거하기<br>피자 나눠먹기 (3)<br>모음 제거 | [23.09.25](./230925.py) |
| 8 | 순서쌍의 개수<br>배열 두배 만들기<br>문자열 안에 문자열<br>중앙값 구하기<br>옷가게 할인 | [23.09.26](./230926.py) |

0 comments on commit b344441

Please sign in to comment.